请问如何才能遍历这个文档内的图片内容,并且读取到 替换文字AlternativeText的内容
谢谢
foreach (Spire.Doc.Section sec in docSpire.Sections)
{
foreach (Spire.Doc.Documents.Paragraph paragraph in sec.Paragraphs)
{
foreach (DocumentObject docObject in paragraph.ChildObjects)
{
Console.WriteLine(docObject.DocumentObjectType);
if (docObject is DocPicture)
{
DocPicture picture = docObject as DocPicture;
Console.WriteLine(picture.AlternativeText);
}
}
}
}
Document doc = new Document();
doc.LoadFromFile("iuouioiou.docx");
foreach (Section sec in doc.Sections)
{
foreach (DocumentObject bodyItem in sec.Body.ChildObjects)
{
if(bodyItem is Paragraph)
{
foreach (DocumentObject docObject in bodyItem.ChildObjects)
{
Console.WriteLine(docObject.GetType());
if (docObject is DocPicture)
{
DocPicture picture = docObject as DocPicture;
Console.WriteLine(picture.AlternativeText);
}
}
}
if(bodyItem is Table)
{
//获取表格
Table table = bodyItem as Table;
for(int i=0;i< table.Rows.Count; i++)
{
//遍历表格行
TableRow row = table.Rows[i];
for(int j = 0; j < row.Cells.Count; j++)
{
//遍历行中单元格
TableCell cell = row.Cells[j];
foreach (DocumentObject docObject in cell.ChildObjects)
{
//遍历单元格中所有子对象 找到段落
if (docObject is Paragraph)
{
//遍历段落中的子对象 找到图片
foreach (DocumentObject paraItem in docObject.ChildObjects)
{
if (paraItem is DocPicture)
{
//打印目标信息
DocPicture picture = paraItem as DocPicture;
Console.WriteLine(picture.AlternativeText);
}
}
}
}
}
}
}
}
}
Console.Read();