I am opening a tab-delimited file in Excel 2010; the delimited file displays correctly in Excel but when I do a save as, to save it as a native Excel 2010 format, the resulting saved file is empty. The resulting saved file generates no errors when debugging and saves with the correct .xlsx extension. Here is the relevant code:
Excel.Application xlApp = null;
Excel.Workbook xlWorkBook = null;
Excel.Worksheet xlWorkSheet = null;
Excel.Range range = null;
object misValue = System.Reflection.Missing.Value;
try
{
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add();
xlApp.Workbooks.OpenText(inputFile, misValue, 1, Excel.XlTextParsingType.xlDelimited, Excel.XlTextQualifier.xlTextQualifierNone, misValue,
misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlApp.Visible = true;
xlApp.DisplayAlerts = false;
xlWorkSheet.SaveAs(outputFile, Excel.XlFileFormat.xlOpenXMLWorkbook, misValue, misValue, misValue, false, misValue, misValue, misValue, misValue);
If I stop execution right after the xlApp.Visible = true
line, I can save the file manually to the .xlsx format and it saves correctly. I figure I have something not set quite right but I'm not sure what it is.