如何使用aspose word for c++在docx文件中插入图片?2.插入图片下面使用自定义题注 图(标签)?3.插入一个表格使用交叉引用之前定义的题注?是否有例子呢?
95798609-1132-465c-a84b-76c7402def8a.png (85.8 KB)
b91d9e8a-0c7b-44c5-b36f-b6de856531ec.png (14.7 KB)
默认没有图这个标签
如何使用aspose word for c++在docx文件中插入图片?2.插入图片下面使用自定义题注 图(标签)?3.插入一个表格使用交叉引用之前定义的题注?是否有例子呢?
95798609-1132-465c-a84b-76c7402def8a.png (85.8 KB)
b91d9e8a-0c7b-44c5-b36f-b6de856531ec.png (14.7 KB)
默认没有图这个标签
@hesijia1234, 以下是插入 3 张带有标题和目录的图像的示例:
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto caption = u"图表";
builder->InsertParagraph();
builder->InsertTableOfContents(u"\\h \\z \\c \"" + caption + "\"");
builder->InsertParagraph();
builder->InsertParagraph();
builder->InsertImage(u"1.jpg");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Caption);
builder->Write(caption + u" ");
builder->InsertField(u"SEQ " + caption + u" \\* ARABIC ");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->InsertParagraph();
builder->InsertImage(u"2.jpg");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Caption);
builder->Write(caption + u" ");
builder->InsertField(u"SEQ " + caption + u" \\* ARABIC ");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->InsertParagraph();
builder->InsertImage(u"3.jpg");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Caption);
builder->Write(caption + u" ");
builder->InsertField(u"SEQ " + caption + u" \\* ARABIC ");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->InsertParagraph();
doc->UpdateFields();
doc->Save(u"out.docx");
files.zip (265.2 KB)
请参阅我们的文档了解更多详细信息:
您好,那请问:1.首先是题注新建标签怎么建?新建的标签名称为"图"
2.在表格个中如何交叉引用题注 这两个问题如何操作呢?感谢您的帮助。
@hesijia1234, 下面的代码示例使用 2 种类型的标题,并根据样式名称(Caption)创建一个目录:
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto caption1 = u"图表";
auto caption2 = u"图";
builder->InsertParagraph();
builder->InsertTableOfContents(u"\\h \\z \\t \"Caption\" \\c");
builder->InsertParagraph();
builder->InsertParagraph();
// 图表 1
builder->InsertImage(u"1.jpg");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Caption);
builder->Write(caption1 + u" ");
builder->InsertField(u"SEQ " + caption1 + u" \\* ARABIC ");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->InsertParagraph();
// 图 1
builder->InsertImage(u"2.jpg");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Caption);
builder->Write(caption2 + u" ");
builder->InsertField(u"SEQ " + caption2 + u" \\* ARABIC ");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->InsertParagraph();
// 图表 2
builder->InsertImage(u"3.jpg");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Caption);
builder->Write(caption1 + u" ");
builder->InsertField(u"SEQ " + caption1 + u" \\* ARABIC ");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->InsertParagraph();
doc->UpdateFields();
doc->Save(u"out.docx");
out.docx (137.0 KB)
在word中添加题注的操作如图
1697597575122.png (32.8 KB)
使用上述方法交叉引用时没有 图 这个标签
image.jpg (98.5 KB)
只有
image.jpg (100.0 KB)
@haomehaode, 可用图标签列表不存储在文档中。 你可以自己检查一下:
1.创建一个新文档,插入一张新图片,为其添加新的图标签。关闭文档并且不保存它。
2. 新建一个文档,插入一张新图片。 前面步骤中的图标签将出现在可用图标签列表中。
因此,Microsoft Word 将可能的图标签列表存储在文档之外的某个位置。Aspose.Words 并不是为了解决这个问题。
@haomehaode, 请检查此代码是否产生所需的结果:
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto caption1 = u"图表";
auto caption2 = u"图";
// 图表 1
builder->InsertImage(u"1.jpg");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Caption);
builder->StartBookmark(u"_Ref100000001");
builder->Write(caption1 + u" ");
builder->InsertField(u"SEQ " + caption1 + u" \\* ARABIC ");
builder->EndBookmark(u"_Ref100000001");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->InsertParagraph();
// 图 1
builder->InsertImage(u"2.jpg");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Caption);
builder->StartBookmark(u"_Ref100000002");
builder->Write(caption2 + u" ");
builder->InsertField(u"SEQ " + caption2 + u" \\* ARABIC ");
builder->EndBookmark(u"_Ref100000002");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->InsertParagraph();
// 图表 2
builder->InsertImage(u"3.jpg");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Caption);
builder->StartBookmark(u"_Ref100000003");
builder->Write(caption1 + u" ");
builder->InsertField(u"SEQ " + caption1 + u" \\* ARABIC ");
builder->EndBookmark(u"_Ref100000003");
builder->InsertParagraph();
builder->get_ParagraphFormat()->set_StyleIdentifier(StyleIdentifier::Normal);
builder->InsertParagraph();
builder->StartTable();
builder->InsertCell();
builder->Write("名称");
builder->InsertCell();
builder->Write(u"图");
builder->EndRow();
builder->InsertCell();
builder->Write(u"酒店");
builder->InsertCell();
builder->InsertField(u"REF _Ref100000001 \\h");
builder->EndRow();
builder->InsertCell();
builder->Write(u"洪崖洞");
builder->InsertCell();
builder->InsertField(u"REF _Ref100000002 \\h");
builder->EndRow();
builder->InsertCell();
builder->Write(u"湖泊");
builder->InsertCell();
builder->InsertField(u"REF _Ref100000003 \\h");
builder->EndRow();
builder->EndTable();
doc->UpdateFields();
doc->Save(u"out.docx");
out.docx (136.9 KB)