I'm not too familiar w/ the PIA assembly's for Office interop (Office 2007) and via .NET/C#, I need to open a workbook and save the first sheet within it as a tab delimited text file. Can someone instruct me on how to do this? Thanks!
views:
101answers:
1
A:
That's quite a big ask mate, but have a look at the below.
[TestMethod()]
public void ExcelTest()
{
Microsoft.Office.Interop.Excel.Application excelApplication = new Application();
string file = @"C:\testsheet.xls";
Microsoft.Office.Interop.Excel.Workbook wkb = excelApplication.Workbooks.Open(
file, 0, false, 5, Missing.Value, Missing.Value, false,
Missing.Value, Missing.Value, true, false, Missing.Value, false, false, false);
Microsoft.Office.Interop.Excel.Worksheet wks = wkb.Worksheets[1] as Microsoft.Office.Interop.Excel.Worksheet;
wks.SaveAs(@"C:\savedFile.txt", Microsoft.Office.Interop.Excel.XlFileFormat.xlTextWindows
, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
Remember to close the application and workbook when you're done or on any errors.
burnside
2010-01-24 23:14:20
Exactly what I was looking for. Thank you!
James Alexander
2010-01-25 01:53:06