Я использую взаимодействие для преобразования файлов .xls в HTML:
if (!File.Exists(path))
CreateExcel(datetime, path);
string inputFileName = path + datetime.ToString("ddMMyyyyHHmmss")+ ".xls";
Microsoft.Office.Interop.Excel.Application excel = null;
Microsoft.Office.Interop.Excel.Workbook xls = null;
try
{
excel = new Microsoft.Office.Interop.Excel.Application();
object missing = Type.Missing;
object trueObject = true;
excel.Visible = false;
excel.DisplayAlerts = false;
xls = excel.Workbooks.Open(inputFileName, missing, trueObject, missing,
missing, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing);
object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
System.Collections.IEnumerator wsEnumerator =
excel.ActiveWorkbook.Worksheets.GetEnumerator();
int i = 1;
while (wsEnumerator.MoveNext())
{
Microsoft.Office.Interop.Excel.Worksheet wsCurrent =
(Microsoft.Office.Interop.Excel.Worksheet)wsEnumerator.Current;
String outputFile = path + datetime.ToString("ddMMyyyyHHmmss")+".html";
wsCurrent.SaveAs(outputFile, format, missing, missing, missing,
missing, missing, missing, missing, missing);
++i;
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
}
finally
{
excel.Application.Quit();
excel.Quit();
Marshal.ReleaseComObject(xls);
Marshal.ReleaseComObject(excel);
excel = null;
}
И в итоге я получаю HTML-файлы без «стилей». Например, документ теряет все цвета, которые имел файл Excel. Чего мне не хватает?