Prev: Standard Audit File for Tax purposes
Next: Scoping
From: Cindy on 14 Dec 2009 18:56 Hello All Could anyone please advise how to create/close/modify .CSV file with VO2.8? could anyone advise which standard lib define class XLApplication? Thanks a lot -Cindy
From: Geoff Schaller on 14 Dec 2009 19:25 Cindy, More information please. It is no different to any other file. MemoRead() and MemorWrit() can and process whole files or you can use Fread etc to mange it line by line. You will know the csv format so there is nothing to tell there. Geoff "Cindy" <cindyliu12(a)gmail.com> wrote in message news:9616e74a-a402-4139-b5dd-9c907161964d(a)a21g2000yqc.googlegroups.com: > Hello All > > Could anyone please advise how to create/close/modify .CSV file with > VO2.8? could anyone advise which standard lib define class > XLApplication? > > Thanks a lot > -Cindy
From: Stephen Quinn on 14 Dec 2009 21:13 Cindy Check the help to see if I have everything correct IF ! File( 'AFile.csv' ) nHandle := FCreate( 'AFile.csv', FC_NORMAL ) ELSE nHandle := FOpen( 'AFile.csv', FO_READONLY or FO_READWRITE ) ENDIF // Do stuff with data file FClose( nHandle ) > could anyone advise which standard lib define class XLApplication? I think you have to import the relevant type library (Automation server/control/object). CYA Steve
From: Marc Verkade [Marti IT] on 15 Dec 2009 05:19 Hai, Here is my MC_CsvLine classs. This is a class that handles CSV lines so you can read them, modify and write them to a file easy! We use it quite extensively for years without any issues. Regards, Marc CLASS MC_CsvLine // MC_CSVLine // No rights or support whatsoever! // Regards, Marc Verkade /* // Usage: // Init the CSV Line with 2 elements oCSV:=MC_CsvLine{2} // Set another seperator (default = ",") oCSV:Seperator:="|" // Import a textline which you can read from a file ofcoarse oCSV:Txt2CSV('6666666;Test',';') // Put some other values in the CSV Line oCSV:PutRow(1, 12345) // Amount oCSV:PutRow(2, "Mr Verkade") // Name // Write a line to a file // Use FileIO to write multiple lines ofcourse! MemoWrit("C:\Test.csv", oCSV:GetLine()) // Extra functions: // oCSV:Reset() // Clears the MC_CSVLine // oCSV:Txt2Csv(sLine,sSeperator) // Parses a string on seperators and puts it into the CSVLine elements */ HIDDEN _ArrayLine AS ARRAY // The CSV line elements HIDDEN _Rows AS DWORD // The amount of elements NOTE : This should be called _Elements! HIDDEN _Quote AS STRING // What character for quoting texts ["] HIDDEN _Seperator AS STRING // What is the seperator [,] HIDDEN _Decimal AS STRING // Decimal sign [.] HIDDEN _No AS STRING // When it is FALSE, what to display [N] HIDDEN _Yes AS STRING // When it is TRUE, what to display [Y] METHOD Init(nRows) CLASS MC_CsvLine IF IsNil(nRows) SELF:_Rows:=0 ELSE SELF:_Rows:=nRows END SELF:_ArrayLine :=ArrayCreate(SELF:_Rows) // Default values SELF:_Quote :='"' SELF:_Seperator :=',' SELF:_Decimal :='.' SELF:_No :='N' SELF:_Yes :='Y' RETURN SELF METHOD GetLine(nKind) CLASS MC_CsvLine // Get's the line with the elements in CSV format // nKind // 0 = Always export empty strings --> "" // 1 = Skip empty slots --> Do not write empty stirngs LOCAL sText AS STRING LOCAL sRow AS STRING LOCAL xRow AS USUAL LOCAL nTeller AS DWORD LOCAL lGo AS LOGIC // Set the deafult kind Default(@nKind,0) sText:=NULL_STRING FOR nTeller:=1 UPTO SELF:_Rows xRow:=SELF:GetRow(nTeller) lGo:=TRUE DO CASE CASE nKind==1 DO CASE CASE !IsString(xRow) // No string, so go! CASE Empty(xRow) lGo:=FALSE CASE Right(Al(xRow),1)=="=" lGo:=FALSE OTHERWISE // Ok, Go! END OTHERWISE // Ok, go END IF lGo // Determine the ValType and add the element DO CASE CASE IsLogic(xRow) IF xRow sRow:=SELF:_No ELSE sRow:=SELF:_Yes END CASE IsNumeric(xRow) sRow:=AsString(xRow) CASE IsString(xRow) sRow:=xRow CASE IsNil(xRow) sRow:=NULL_STRING CASE Empty(xRow) sRow:=NULL_STRING OTHERWISE sRow:=AsString(xRow) END // Check for the seperator and decimal DO CASE CASE SELF:_Decimal=="," sRow:=StrTran(sRow,".",",") CASE SELF:_Decimal=="." sRow:=StrTran(sRow,",",".") OTHERWISE // Nothing! END IF !Empty(SELF:_Seperator) sRow:=StrTran(sRow,SELF:_Seperator,"-") END // Add the element IF Empty(SELF:_Seperator) sText+=sRow ELSE sText+=AllTrim(sRow) sText+=SELF:_Seperator END END NEXT nTeller // Strip the last seperator IF !Empty(SELF:_Seperator) IF Right(sText,1)==SELF:_Seperator sText:=Left(sText,Len(sText)-1) END END RETURN sText METHOD GetRow(nRow) CLASS MC_CsvLine // Gets the Nth element of the line LOCAL xText AS USUAL IF nRow>SELF:_Rows .OR. nRow<0 // Use your own errorbox! MC_ErrorBox("MC_CSVLine element is not valid!") ELSE xText:=SELF:_ArrayLine[nRow] END RETURN xText METHOD PutRow(nRow,xText,lUseQuote) CLASS MC_CsvLine // Puts an element in the CSV Default(@lUseQuote,FALSE) IF nRow>SELF:_Rows .OR. nRow<0 // Use your own errorbox! MC_ErrorBox("CSV Element number is not valid!") ELSE DO CASE CASE IsString(xText) IF lUseQuote xText:=SELF:_Quote+AllTrim(xText)+SELF:_Quote END END SELF:_ArrayLine[nRow]:=xText END RETURN xText ASSIGN Quote(sQuote) CLASS MC_CsvLine RETURN SELF:_Quote:=sQuote METHOD Reset() CLASS MC_CsvLine // Reset the elements LOCAL nTeller AS DWORD FOR nTeller:=1 UPTO SELF:_Rows ADel(SELF:_ArrayLine,nTeller) NEXT nTeller RETURN NIL ACCESS Seperator CLASS MC_CsvLine RETURN SELF:_Seperator ASSIGN Seperator(sSeperator) CLASS MC_CsvLine RETURN SELF:_Seperator:=sSeperator METHOD Txt2Csv(sLine,sSeperator) CLASS MC_CsvLine // Parses a string on seperators and puts it into the CSVLine elements LOCAL aData AS ARRAY LOCAL nTeller AS DWORD aData:=MC_String2Array(sLine,sSeperator) FOR nTeller:=1 UPTO ALen(aData) SELF:PutRow(nTeller,aData[nTeller]) NEXT nTeller RETURN NIL ACCESS Decimal CLASS MC_CsvLine RETURN SELF:_Decimal ASSIGN Decimal(sDecimal) CLASS MC_CsvLine RETURN SELF:_Decimal:=sDecimal Furthermore the MC_String2Array function FUNCTION MC_String2Array(cString,xSep) LOCAL cSubstring AS STRING LOCAL cSubLetter AS STRING LOCAL nCount AS DWORD LOCAL aRetVal AS ARRAY // Init vars aRetVal:=ArrayCreate(0) // Check de parameters DO CASE CASE Empty(xSep) xSep:={'#'} CASE IsString(xSep) xSep:={xSep} CASE IsArray(xSep) // OK END // Add an extra delimter to the end // Perhaps perform a right[1] check to see if the last one is a delimiter... cString+=xSep[1] FOR nCount:=1 UPTO Len(cString) cSubLetter:=(SubStr(cstring,nCount,1)) IF AScan(xSep,cSubLetter)==0 // Normal character, add to the cSubstring:=cSubstring+cSubletter ELSE // We found a delimter, add the value to the return array // BB20091117 added an alltrim here, because otherwise the last value is full will spaces AAdd(aRetVal,Alltrim(cSubstring)) cSubString:="" END NEXT nCount RETURN aRetVal -- Grtz, Marc "Cindy" <cindyliu12(a)gmail.com> schreef in bericht news:9616e74a-a402-4139-b5dd-9c907161964d(a)a21g2000yqc.googlegroups.com... > Hello All > > Could anyone please advise how to create/close/modify .CSV file with > VO2.8? could anyone advise which standard lib define class > XLApplication? > > Thanks a lot > -Cindy
From: Malcolm on 15 Dec 2009 06:18
On 15/12/2009 02:13, Stephen Quinn wrote: > Cindy > > Check the help to see if I have everything correct > > IF ! File( 'AFile.csv' ) > nHandle := FCreate( 'AFile.csv', FC_NORMAL ) > ELSE > nHandle := FOpen( 'AFile.csv', FO_READONLY or FO_READWRITE ) > ENDIF > // Do stuff with data file > FClose( nHandle ) And course remember CSV comes in many dialects >> could anyone advise which standard lib define class XLApplication? > I think you have to import the relevant type library (Automation > server/control/object). Agreed - it is usually the Excel COM automation class |