• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1438
  • Last Modified:

Save excel file as text(tab delimited) file programmaticly(c#)

Hello,

I have an excel file, can I save it as text(tab delimited) file programmaticly(c#)?
And vice versa?

Thanks for your code snippet.
0
zhshqzyc
Asked:
zhshqzyc
  • 3
  • 3
1 Solution
 
yjchong514Commented:
Method you are looking for is Workbook.SaveAs with parameter FileFormat=xlText
0
 
zhshqzycAuthor Commented:
But there is not such a type "xlText".
Please see here.
0
 
regmigrantCommented:
i looked at the link you provided and there are several CSV and Text formats to choose from - is there something more specific you are looking for beyond:-

xlCSV  Comma separated value.  
xlCSVMac  Comma separated value.  
xlCSVMSDOS  Comma separated value.  
xlCSVWindows  

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
zhshqzycAuthor Commented:
tab delimited
0
 
regmigrantCommented:
A text file can't contain a macro so I am assuming you are using one workbook to save another - in which case you could just write the output as a data stream and use whatever delimiter you want.


Another option is to open a tab delimited file with dummy data in it - this will set the default for that worksheet to be Text (tab delimited) then clear it, populate it and when you save it it will use the default - though you will probably have to deal with the warning dialog making sure you want to save as text

0
 
zhshqzycAuthor Commented:
Well, I need some code anyway. Can we save it as csv then save csv to text(tab delimited)?
0
 
regmigrantCommented:
The .csv filetype is assumed to use comma's as a seperator (the clue is in the name) and excel will try and open it that way. You can create a dummy file with tabs and that will force the sheet to be 'text (tab delimited)' then when you save it replace the extension and it preserves the tab format.

so your macro would have to open the dummy file, deal with the text import dialog, populate the sheet, and save with the new filename.

The alternative is to open a text file from within the macro, write your tab delimited records to it and the close it. To get a tab into the record you use chr(9)

MyStr = "Hello" & chr(9) & " World"

Open "TESTFILE.csv" For Output As #1
write #1, Mystr
Close #1

will give you a tab delimited file with a .csv filetype




0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now