Need to convert Excel sheets into Text (tab delimited ) as in MS Excel 2007 programatically using C#
Ok, here is the problem MS Excel allows me to save the whole sheet as text tab delimited I'm using this text in a program , but the user needs to make the previous step manually 开发者_如何学Go I want to automate this step so the user only import the Excel Book into my program , and shows how many sheets inside it letting the user select the desired sheet and then the program will convert this sheet into text (tab delimited ) , any ideas ?
Well... one of the easiest to learn methods would be the use Excel Interop. The downside of this method is it (1.) requires Excel to be installed and (2.) Can get messy very quickly... but generally it makes sense.
I suggest familiarizing yourself with Excel Interop. Now, take note of the SaveAs method for the Workbook object.
- Loop through the Worksheets property of the opened Workbook.
- Display the sheet names for the user to choose.
- Get the desired sheet by name and access the Worksheet object
- Use the desired Worksheet's Select method
- Use the Workbook's SaveAs method. Be sure to use FileFormat option to make it tab delimited.
Hope that helps. Just remember, it's doable.
There are several options:
- OpenXML 2.0 from MS - http://msdn.microsoft.com/en-us/library/bb448854.aspx...
It is a free library that does NOT require office to be installed... you can read + write Office files including Excel and Word (Version 2007 and up...). - VSTO/Office Interop from MS - http://msdn.microsoft.com/en-US/office/hh128771.aspx
this need Office to be installed and works only in desktop apps (NOT services or ASP.NET..) and let's you automate whatever you want...
精彩评论