private void ShowPreview()
{
// 使用Excel Interop打开文件
Excel.Application excelApplication = new Excel.Application();
var name = @"C:\Users\nbDesktop\报告表.xlsx";
Excel.Workbook workbook = excelApplication.Workbooks.Open(name,false);
// 生成HTML文件
string htmlFilePath = string.Format("{0}{1}.html", Path.GetTempPath(), Path.GetFileNameWithoutExtension(name));
if (!Directory.Exists(Path.GetTempPath()))
{
Directory.CreateDirectory(Path.GetTempPath());
}
Excel.Worksheet sh = workbook.ActiveSheet;
sh.SaveAs(htmlFilePath, Excel.XlFileFormat.xlHtml);
// 使用WebBrowser控件来显示预览
WebBrowser previewBrowser = new WebBrowser();
previewBrowser.Navigate(htmlFilePath);
previewBrowser.Dock = DockStyle.Fill;
// 创建窗口并显示预览
this.Controls.Add(previewBrowser);
}
11-26
660
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)