你好,这是我的问题。我目前有一个具有 Web 浏览器控件的独立 WPF 应用程序。我有一些 C# 代码,它生成一个 HTML 页面,我将其用作 Web 浏览器的内容。我的问题是我正在尝试将此 HTML 页面导出到 excel 并包含其中的图像。这就是我目前将 HTML 导出到 EXCEL 文件的方式:
string filePath = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".html";
//Creates an HTML file from the web browser and save it to a temp location
File.WriteAllText(filePath, GenerateHtml());
//Creates a new instance of Microsoft office interop for using MS Excel
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
//Create a new instance of a workbook
Microsoft.Office.Interop.Excel.Workbook excelWorkBook = excelApp.Workbooks.Add();
//Don't Show MS Excel
excelApp.Visible = false;
//Open a file at location
Microsoft.Office.Interop.Excel.Workbook excelWorkBook2 = excelApp.Workbooks.Open(filePath);
//Convert that file to an XLSX document
SaveFileDialog newSFD = new SaveFileDialog();
newSFD.FileName = "Report in Excel Format";
newSFD.DefaultExt = ".xls";
newSFD.Filter = "XLS Documents (.xls)|*.xls";
Nullable<bool> result = newSFD.ShowDialog();
if (result == true)
{
string fileName = newSFD.FileName;
excelWorkBook2.SaveAs(fileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlXMLSpreadsheet, Missing.Value, Missing.Value, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlUserResolution, true, Missing.Value, Missing.Value, Missing.Value);
//Close excel
excelApp.Quit();
}
一切都可以导出,所有信息都在那里,但由于某种原因没有图像。图像应该在那里的桌子在那里,它有图像应该去的地方占位符,这就是为什么我很困惑。如果需要更多解释,请告诉我,我会提供,否则感谢您对此问题的帮助/关注。