Hi,
Can the combination of Spire.Doc and Spire.XLS read a .docx file and convert embedded Excel spreadsheets into Word Tables? If not, what would be needed in order to accomplish this?
Cheers,
Alex
Document doc = new Document("Sample.docx", Spire.Doc.FileFormat.Docx2010);
Section section = doc.Sections[0];
Paragraph para = section.Paragraphs[2];
DataTable dt = new DataTable();
foreach (DocumentObject obj in para.ChildObjects)
{
if (DocumentObjectType.OleObject == obj.DocumentObjectType)
{
DocOleObject dObj = obj as DocOleObject;
if (dObj.ObjectType == "Excel.Sheet.12")
{
Workbook wb = new Workbook();
wb.LoadFromStream(new MemoryStream(dObj.NativeData));
Worksheet ws = wb.Worksheets[0];
dt = ws.ExportDataTable(ws.AllocatedRange, false);
}
}
}
Table table = section.AddTable(true);
table.ResetCells(dt.Rows.Count, dt.Columns.Count);
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
string text = dt.Rows[i][j] as string;
table.Rows[i].Cells[j].AddParagraph().AppendText(text);
}
}
doc.SaveToFile("4380.docx", Spire.Doc.FileFormat.Docx2010);