Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
10
Erster Beitrag:
vor 7 Jahren, 6 Monaten
Letzter Beitrag:
vor 1 Monat
Beteiligte Autoren:
Piet van Zanten, DarrenF, Hans60, Guenter PREDL, GuenterP, Arie, miko

Export FIC data to txt file

Startbeitrag von miko am 18.06.2010 12:40

Hi all,

I'm sure this has been requested many times although the forum search engine didn't return any match.

I have this FIC file from a software that I need to export data from to import them in another software. An export in txt, xml, csv or anything else would be great.

I've already tried to used the software made by Dominique Daussy (for windev 5.5 file) and it didn't work. So I'm guessing the version used to produce the software must be higher.

If anyone can point me in the right direction, I'd appreciate it.

Thanks

Michael

Antworten:

If you load the data in a table control you can call
TableToText, TableToClipboard, TableToExcel, TableToXML.
You can also use HExportXML() to export the data directly.
You mention a very old example, but I don't know which versions of WD do support the function above. WD12 and higher do. I don't know about older versions.

von Arie - am 18.06.2010 12:58
Hi Michael,

If Arie's suggestion(s) aren't acceptable or you need to do some processing on the data before writing it out, I can let you have some example code that loops thru a table writing out to a text file?

Let me know if you need it...

HTH

von DarrenF - am 18.06.2010 14:12
Darren... I am interested in that too... Thanks! dev at ch4 dot net

von Hans60 - am 18.06.2010 14:54
Hi guys,

I've posted something in the WinDev solutions area for you to take a look at :spos:

http://forum.mysnip.de/read.php?27161,69354

von DarrenF - am 18.06.2010 17:15
Hi Michael,

This function dumps a file into a textfile separated by tabs. It takes into account dimensioned items.
// Syntax:
//[ Result = ] DumpFile (sFileName, bItemNames)
//
// Parameters:
// sFileName: name of sFileName to dump
// bItemNames: Flag to switch on exporting itemnames in header
// Return Value:
// boolean: // output interrupted

FUNCTION DumpFile(sFileName,bItemNames)
ar_ItemName is array dynamic of 0 string
ar_Dimension is array dynamic of 0 int
i,j,nItemCount,nfHandle is int
sItemNames,sLine,sCurrentItem are string

pb_ProgressBar1..MaxValue=HNbRec(sFileName)
pb_ProgressBar1=0
pb_ProgressBar1..Caption=sFileName
pb_ProgressBar1..Visible=True
MultitaskRedraw()

nfHandle=fOpen(CompleteDir(sDataPad)+Lower(sFileName)+".txt",foCreate)

sItemNames=HListItem(sFileName,hLstDetail)
//explode itemnames
FOR EACH STRING sCurrentItem OF sItemNames SEPARATED BY CR
ArrayAdd(ar_ItemName,ExtractString(sCurrentItem,1))
ArrayAdd(ar_Dimension,Val(ExtractString(sCurrentItem,5)))
END

IF bItemNames THEN
//write header
FOR i=1 _TO_ ArrayInfo(ar_ItemName,tiDimension)
IF ar_Dimension>1 THEN
FOR j=1 _TO_ ar_Dimension
sLine+=ar_ItemName+"_"+j+TAB
END
ELSE
sLine+=ar_ItemName+TAB
END
END
sLine=sLine[[1 TO Length(sLine)-1]] //remove final tab
fWriteLine(nfHandle,sLine)
END

nItemCount=ArrayInfo(ar_ItemName,tiDimension)

FOR EACH sFileName
IF EscTest() THEN //function to test if escape is pressed
fClose(nfHandle)
pb_ProgressBar1..Visible=False
RESULT False
END
pb_ProgressBar1++
sLine=""
FOR i=1 TO nItemCount
FOR j=1 _TO_ ar_Dimension
sCurrentItem={sFileName+"."+ar_ItemName,indItem}[j]
sCurrentItem=Replace(sCurrentItem,CR,"") //replace cr to prevent messing up the output
sCurrentItem=Replace(sCurrentItem,TAB,"") //replace tab to prevent messing up the output
sLine+=sCurrentItem+TAB
END
END
sLine=sLine[[1 TO Length(sLine)-1]] //remove final tab
fWriteLine(nfHandle,sLine)
END
fClose(nfHandle)
pb_ProgressBar1..Visible=False
RESULT True
Regards,
Piet


von Piet van Zanten - am 18.06.2010 18:46
Thank you Piet and DarrenF !

von Hans60 - am 18.06.2010 21:19

Re: Export FIC data to txt file

Hi Piet,

your fic => txt export-program doesn't run, there are some problems. Maybe, because it is 7 years old already? Do you have a better / more recent version of the program? Please post it if you have a newer version available! Thank you!

von GuenterP - am 12.11.2017 07:52

Re: Export FIC data to txt file

Hi Guenter,

This is a more recent version, it includes the option export to Excel. I use it in Webdev and it's fully operational.

FUNCTION DumpFile(sFileName,nOption)
stItem is Structure
sItemName is string
nDimension is int
END
ar_Items is array of stItem
ensStItem is stItem
i,j,nItemCount,nRow,nCol is int
sFile,sItemNames,sLine,sCurrentItem are string

sItemNames=HListItem(sFileName,hLstDetail)
//explode itemnames
FOR EACH STRING sCurrentItem OF sItemNames SEPARATED BY CR
ensStItem.sItemName=ExtractString(sCurrentItem,1)
ensStItem.nDimension=Val(ExtractString(sCurrentItem,5))
ArrayAdd(ar_Items,ensStItem)
END
nItemCount=ArrayInfo(ar_Items,tiDimension)
sFile=CompleteDir(sTempPath)+Lower(sFileName)

IF nOption=1 THEN
//Excel
nRow=1
nCol=1
myWorksheet is xlsDocument
xlsAddWorksheet(myWorksheet,"Blad1")
FOR i=1 TO nItemCount
IF ar_Items.nDimension>1 THEN
FOR j=1 _TO_ ar_Items.nDimension
myWorksheet[nRow,nCol]=ar_Items.sItemName+"_"+j
nRow++
nCol++
END
ELSE
myWorksheet[nRow,nCol]=ar_Items.sItemName
nCol++
END
END
nRow++
FOR EACH sFileName
sLine=""
nCol=1
FOR i=1 TO nItemCount
FOR j=1 _TO_ ar_Items.nDimension
myWorksheet[nRow,nCol]={sFileName+"."+ar_Items.sItemName,indItem}[j]
nCol++
END
END
nRow++
END
xlsSave(myWorksheet,sFile+".xls")
ELSE
//text
sContent is string
//write header
FOR i=1 TO nItemCount
IF ar_Items.nDimension>1 THEN
FOR j=1 _TO_ ar_Items.nDimension
sLine+=ar_Items.sitemname+"_"+j+TAB
END
ELSE
sLine+=ar_Items.sitemname+TAB
END
END
sContent=sLine
FOR EACH sFileName
sLine=""
FOR i=1 TO nItemCount
FOR j=1 _TO_ ar_Items.nDimension
sCurrentItem={sFileName+"."+ar_Items.sitemname,indItem}[j]
sCurrentItem=Replace(sCurrentItem,CR,"") //replace cr to prevent messing up the output
sCurrentItem=Replace(sCurrentItem,TAB,"") //replace tab to prevent messing up the output
sLine+=sCurrentItem+TAB
END
END
sLine=sLine[[2 TO ]]
sContent+=sLine+CR
END
fSaveText(sFile+".txt",sContent)
END
RESULT True

Creating a zipped backup with this procedure from a table containing the filenames and a checkbox to select them:

i is int
sFile,sExt is string

FOR i=1 _TO_ TableCount(Table_Files)
IF col_Check THEN
IF NOT DumpFile(col_Bestand,radio_Output) THEN BREAK
END
END
//create zipfile
IF radio_Output=1 THEN
sExt=".xls"
ELSE
sExt=".txt"
END
sBackupFile=sTempPath+"backup.zip"
zipCreate("a1",sBackupFile)
FOR i=1 _TO_ TableCount(Table_Files)
IF col_Check THEN
sFile=sTempPath+col_Bestand+sExt
zipAddFile("a1",sFile,zipNone)
fDelete(sTempPath+col_Bestand+sExt)
END
END
zipClose("a1")
btn_Download..Visible=True
proc_Info("Backup ready"+RC+"press [Download] button to download.")



Kind regards,
Piet

von Piet van Zanten - am 13.11.2017 10:33

Re: Export FIC data to txt file

Hi Piet,

thanks a lot! I didn't want to leave it as it is in the forum's repository! Here's my dump function. Most probably, I took the basic source code from some French forum quite a few years ago and reworked it a bit. The problem with posting this code her is the disappearance of the square brackets and their contents, so I put it in the editor ...
[attachment 2498 MyDumpFile_Function.rtf]

Btw, this is no rtf-document, it's a simple txt one. But it wouldn't accept a txt for upload ... however, it displays just fine in WordPad ...

Please check, whether your posted code matches the original! Thank you!

kind regards,
Guenter

von Guenter PREDL - am 13.11.2017 15:46
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.