Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: JaiPrakash Bhandari
  Where is JaiPrakash Bhandari?
 Hyderabad
 India
 JaiPrakash Bhandari
 Tags
Subject: RE: Save As 'Txt to Xls'
Thread ID: 228461 Message ID: 228510 # Views: 2 # Ratings: 0
Version: Visual FoxPro 9 Category: Active X Controls & OLE Automation
Date: Tuesday, May 19, 2009 2:43:09 PM         
   


> Hello!
> I have an TAB separated text file, and I want to Save it as .Xls by not opening the file.
> Is it possible programmatically through VFP ?
> This is required as I want to get the values on the Excel sheet.
>
> Regards
> Bhandari

You should be kidding. Saving as an excel files requires that you read the file and I don't think that there is a way to read a file w/o opening it. If you meant to cheat, then yes you can cheat and change the file's extension to CSV (provided first line would have comma delimited column headers). If we agree on that you need to open the file then you could do that in multiple ways. One way is to use PasteSpecial:

*!*	Select * FROM (_samples+'data\customer') into Cursor myData

Local lcTextFileName, lcXLSFileName
lcTextFileName = "c:\temp\MyTabDelimitedText.txt"
*!*	lcTextFileName = FORCEPATH(Sys(2015)+'.tmp',SYS(2023))

Copy To (m.lcTextFileName) Type Delimited With "" With Tab
_Cliptext = Filetostr(m.lcTextFileName)

*!*	Erase (m.lcTextFileName)

lcXLSFileName = "c:\temp\MyTabDelimitedText.xls"

oExcel = Createobject("excel.application")
With oExcel
  .Workbooks.Add
  .ActiveWorkBook.ActiveSheet.Range('A1').PasteSpecial()
  .ActiveWorkBook.SaveAs(m.lcXLSFileName)
  .ActiveWorkBook.Saved = .t.
  .Quit
Endwith


PS: The proper way of transferring data from VFP to Excel is VFPOLEDB IMHO.

Cetin Basoz

.Net has got better.Think about moving - check my blog:
Blog (main)
Blog (mirror)

ENTIRE THREAD

Save As 'Txt to Xls' Posted by JaiPrakash Bhandari @ 5/19/2009 8:08:09 AM
RE: Save As 'Txt to Xls' Posted by Stefan Wuebbe @ 5/19/2009 10:30:20 AM
RE: Save As 'Txt to Xls' Posted by Yousfi Benameur @ 5/19/2009 10:47:47 AM
RE: Save As 'Txt to Xls' Posted by Cetin Basoz @ 5/19/2009 2:43:09 PM