Write .txt file in excel .xlsx

Just starting out? Need help? Post your questions and find answers here.
lixbl
New User
New User
Posts: 1
Joined: Tue May 25, 2021 10:23 am

Write .txt file in excel .xlsx

Post by lixbl »

Hello there.

I have a text file with data format: 5 words at every string and 100+ strings.
I allready know how to read strings from file, but I'm stuck searching for writing to excel solution.
I try COMatePLUS, but it give me an error at 35 string, and I've tried use libxl, but it also gives me a linker error.
I didn't find any solutions about that problems. Help me please. Thanks

Code: Select all


DisableExplicit
IncludePath #PB_Compiler_Home + "libxl-3.9.4.3" + "\" + "lib"
ImportC "libxl.lib"
xlCreateBookW.i()
xlBookReleaseW.i(book.i)
xlBookAddSheetW.i(book.i,sheet.s,flag.i)
xlSheetWriteStrW.i(sheet.i,x.i,y.i,string.s,flag.i)
xlSheetWriteNumW.i(sheet.i,x.i,y.i,value.i,flag.i)
xlBookSaveW.i(book.i,save.s)
xlBookLoadW(book.i,filename.s, tempfile.s)
EndImport

Global book.i
Global sheet.i
Define bret.i

book = xlCreateBookW()
If book
  sheet = xlBookAddSheetW(book, "sheet1", #Null)
  If sheet
    xlSheetWriteStrW(sheet,2,2,"Hello world!",#Null)
    xlSheetWriteNumW(sheet,3,1,1000,#Null)
    xlBookSaveW(book,"test.xls")
  EndIf
  xlBookReleaseW(book) 
 EndIf
Procedure StrCp() 
  If ReadFile(0, "inv_temp.txt") ;;if the file could be read we continue
    While Eof(0) = 0 ;;loop as long the 'end of file' isn't reached
      Text.s = ReadString(0) ;;write file to string
      Debug Text    
    Wend
    CloseFile(0)
    Debug i
  EndIf
EndProcedure

Procedure StrPst()
    
EndProcedure

StrCp()