Import excel table sheet in word by aspose.word for C# .Net

Import excel table sheet in word by aspose.word for C# .Net

我有一个 excel 文件,我想从中导入一个 sheet 到我的 .DOCXaspose.word 创建的文件。我尝试了 InsertOleObject 但是没有显示任何 table 并且只显示了一个对象形状链接到 excel 文件。

遗憾的是,没有直接的方法将 Excel 文档转换为 Word。但是,在 Aspose.Cells 和 Aspose.Pdf 的协作下是可能的。首先使用 Aspose.Cells 将 Excel 文档转换为 PDF,然后使用 Aspose.Pdf 将 PDF 文档转换为 Word 文档。为此,请检查以下示例代码。

//Use Aspose.Cells to convert XLS to Word document
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook("Book1.xls");
// To convert first sheet only you need to hide other worksheets
workbook.Worksheets[1].IsVisible = false;
// Save the XLS document into PDF document
workbook.Save("output.pdf", Aspose.Cells.SaveFormat.Pdf);
//Use Aspose.Pdf to convert PDF to Word document
// Open the source PDF document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document("output.pdf");
// Save the PDF file into Word document
pdfDocument.Save("PDFToDOCX_out.docx", Aspose.Pdf.SaveFormat.DocX);

我在 Aspose 工作,担任开发人员布道师。