'Loop through the document object under a certain sectionįor Each documentObject In 'Loop through the sections in the Word document Switch ()Ĭ = HorizontalAlignType.Left Ĭ = HorizontalAlignType.Center Ĭ = HorizontalAlignType.Right ĭoc.LoadFromFile("C:\Users\Administrator\Desktop\Invoice.docx")ĭim worksheet As Worksheet = wb.CreateEmptySheet("WordToExcel") RichText.SetFont(startIndex, endIndex, font) ĭocPicture picture = documentObject as DocPicture Ĭ(cell.Row, cell.Column, picture.Image) Ĭ(cell.Row, 1, ) String fontName = īool isBold = Ĭolor textColor = įloat fontSize = ĮxcelFont font = () TextRange textRange = documentObject as TextRange Private static void CopyTextAndStyle(CellRange cell, Paragraph paragraph)įoreach (DocumentObject documentObject in paragraph.ChildObjects) Copy text and style of a paragraph to a cell Paragraph newPara = new Paragraph(tbCell.Document) įor (int i = 0 i < i++)ĭocumentObject documentObject = tbCell.ChildObjects įoreach (DocumentObject cObj in paragraph.ChildObjects) Private static void Cop圜ontentInTable(TableCell tbCell, CellRange cell) Copy content from a Word table cell to an Excel cell Private static int ExportTableInExcel(Worksheet worksheet, int row, Table table)įoreach (TableCell tbCell in tbRow.Cells)Ĭell.BorderAround(LineStyleType.Thin, Color.Black) Export data from Word table to Excel cells Wb.SaveToFile("WordToExcel.xlsx", ExcelVersion.Version2013) Int currentRow = ExportTableInExcel(worksheet, row, table) Copy paragraph from Word to a specific cell Paragraph paragraph = documentObject as Paragraph Loop through the document object under a certain sectionįoreach (DocumentObject documentObject in )ĬellRange cell = worksheet.Range Loop through the sections in the Word documentįoreach (Section section in doc.Sections) Worksheet worksheet = wb.CreateEmptySheet("WordToExcel") Save the workbook to an Excel file using Workbook.SaveToFile() method.Auto fit the row height and column width in Excel so that the data within a cell will not exceed the bound of the cell.If the document object is a table, export the table data from Word to Excel cells using ExportTableInExcel() method.If the document object is a paragraph, write the paragraph in a specified cell in Excel using CoypTextAndStyle() method.Traverse though all the sections in the Word document, traverse through all the document objects under a certain section, and then determine if a document object is a paragraph or a table.Create a Worbbook object and add a worksheet named "WordToExcel" to it.Create a Document object to load a Word file.The following steps demonstrate how to export data from an entire Word document to a worksheet using Spire.Office for. CopyTextAndStyle() - Copy text with formatting from a Word paragraph to an Excel cell.Cop圜ontentInTable() - Copy content from a table cell in Word to an Excel cell.ExportTableInExcel() - Export data from a Word table to specified Excel cells.To make this code example easy to understand, we created the following three custom methods that preform specific functions. The former is used to read and extract content from a Word document, and the latter is used to create an Excel document and write data in the specific cells. This scenario actually uses two libraries in the Spire.Office package. The converter is always available online and is completely free.PM> Install-Package Spire.Office Convert Word to Excel in C# and VB.NET You can convert your documents from anywhere, from any machine or even from a mobile device. All documents are removed from the cloud after 24 hours. Expand the ConvertOptions and fill the fields for watermarking.Ĭonverted files are stored in the cloud. Or you can add a watermark to the converted file. Just expand LoadOptions and enter the password of your file. For example you can convert password protected documents. You even can perform more advanced conversions. Once conversion completed you can download your file. Just drag and drop your file on upload form, choose the desired output format and click convert button. You can convert your documents from any platform (Windows, Linux, macOS).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |