Hello,
I want use Spire.doc 7.10 to read txt or table Content controls(Rich text) of the word2016 . I find it is different from the Content controls which spire.doc generated。
What can i do for this issue?
Betsy.jiang wrote:Hi,
Thanks for your inquiry.
Please provide your input Word file and the code you were using for further investigation.
BTW, we provide Chinese service. You could contact us in Chinese next time if you want.
Sincerely,
Betsy
E-iceblue support team
Document document = new Document();
document.LoadFromFile(wordFile);
foreach (Section section in document.Sections)
{
foreach (DocumentObject objbody in section.Body.ChildObjects)
{
if (objbody.DocumentObjectType == DocumentObjectType.StructureDocumentTag) //判断控件
{
StructureDocumentTag sdt = objbody as StructureDocumentTag;
foreach (DocumentObject sdtobj in sdt.ChildObjects)
{
if (sdtobj.DocumentObjectType == DocumentObjectType.Table) //判断控件-表格
{
Table tab = sdtobj as Table;
neirong = (5 * tab.Rows.Count).ToString();
foreach (TableRow tr in tab.Rows)
{
foreach (TableCell cell in tr.Cells)
{
foreach (Paragraph con in cell.Paragraphs)
{
dt.Rows.Add( (con.Text);
}
}
}
}
else if (objbody.DocumentObjectType == DocumentObjectType.StructureDocumentTag) //控件中控件
{
StructureDocumentTag sdtcell = objbody as StructureDocumentTag;
foreach (DocumentObject sdto in sdtcell.ChildObjects)
{
if (sdto.DocumentObjectType == DocumentObjectType.Paragraph)
{
dt.Rows.Add( (sdto as Paragraph ).Text);
}
}
}
}
} else if (objbody.DocumentObjectType == DocumentObjectType.Paragraph) //判断图片
{
Paragraph par = objbody as Paragraph;
foreach (DocumentObject picturex in objbody.ChildObjects)
{
if (picturex.DocumentObjectType == DocumentObjectType.Picture)
{
DocPicture pic =picturex as DocPicture;
imagelist.Add(pic.Image);
}
}
}
}
}
Betsy.jiang wrote:Hi,
Greetings from E-iceblue.
Has your issue been resolved? If not, could you please provide your input Word file and the code you were using for further investigation.
Sincerely,
Betsy
E-iceblue support team
sd = new StructureDocumentTag(doc);
section.Body.ChildObjects.Add(sd);
DataTable ds = spltbiao(dt.Rows[i][5].ToString());
Table ta = new Table(doc ) ;
ta.ResetCells(ds.Rows.Count, ds.Columns.Count); ta.DefaultColumnWidth = 20F;
TextRange range= new TextRange (doc);
range.CharacterFormat.FontName = "Arial";
range.CharacterFormat.FontSize = 10;
range.CharacterFormat.CharacterSpacing = 0;
range.CharacterFormat.TextColor = Color.Black;
range.CharacterFormat.Bold = true;
for (int ix = 0;ix<ds.Rows .Count;ix++)
{
ta.Rows[ix].Height = 20F;
for (int iy = 0; iy < ds.Columns.Count; iy++)
{
range.Text = ds.Rows[ix][iy].ToString ();
ta[ix, iy].AddParagraph().AppendText(range.Text);
}
}
sd.SDTContent.ChildObjects.Add(ta);
Paragraph par = ta[ix, iy].AddParagraph();
par.Format.BeforeSpacing = 0;