Spire.XLS Standard Edition 12.12 已发布。该版本修复了保存文档时,程序抛出"Some parts of this workbook may have been repaired or discarded"异常的问题。详情请阅读以下内容。
问题修复:
图像可以为文档增加视觉多样性,并传达难以仅通过文本表达的信息,例如复杂的概念或情感。它们是使您的文档更易于理解、更具吸引力和更令人难忘的强大工具。无论您是设计报告还是创建营销文档,插入图像都可以增强您与读者的沟通,并给他们留下持久的印象。在本文中,您将学习如何使用 Spire.Doc for C++ 将图像插入到 Word 文档中。
有两种方法可以将 Spire.Doc for C++ 集成到您的应用程序中。一种方法是通过 NuGet 安装它,另一种方法是从我们的网站下载包并将库复制到您的程序中。通过 NuGet 安装更简单,更推荐使用。您可以通过访问以下链接找到更多详细信息。
如何将 Spire.Doc for C++ 集成到 C++ 程序中
Spire.Doc for C++ 提供了 Paragraph->AppendPicture() 方法来将图像插入到 Word 文档中。 详细步骤如下:
#include "Spire.Doc.o.h"
using namespace Spire::Doc;
using namespace Spire::Common;
int main()
{
//创建Document的对象
intrusive_ptr<Document> document = new Document();
//添加一个节
intrusive_ptr<Section> section = document->AddSection();
//添加第一段
intrusive_ptr<Paragraph> paragraph1 = section->AddParagraph();
//向段落中添加文本并设置格式
intrusive_ptr<TextRange> tr = paragraph1->AppendText(L"Spire.Doc for C++ 是一款专门对 Word 文档进行操作的 C++ 类库。这款控件的主要功能在于帮助开发人员轻松快捷高效地创建、编辑、转换、及比较Microsoft Word 文档。");
tr->GetCharacterFormat()->SetFontName(L"宋体");
tr->GetCharacterFormat()->SetFontSize(11.0f);
paragraph1->GetFormat()->SetLineSpacing(20.0f);
paragraph1->GetFormat()->SetAfterSpacing(10.0f);
//增加第二段
intrusive_ptr<Paragraph> paragraph2 = section->AddParagraph();
//向段落中添加文本并设置格式
tr = paragraph2->AppendText(L"Spire.Doc for C++ 支持几乎所有的 Word 文档元素,包括页面、部分、页眉、页脚、数字签名、脚注、段落、列表、表格、文本、字段、超链接、书签、评论、图像、样式、背景设置 ,文件设置和保护。此外,还支持绘图对象,包括形状、文本框、图像、OLE 对象、Latex 数学符号、MathML 代码和控件。");
tr->GetCharacterFormat()->SetFontName(L"宋体");
tr->GetCharacterFormat()->SetFontSize(11.0f);
paragraph2->GetFormat()->SetLineSpacing(20.0f);
//将图像添加到第一段
intrusive_ptr<DocPicture> picture = paragraph1->AppendPicture(L"Doc-CPP.png");
//设置图像宽度和高度
picture->SetWidth(100);
picture->SetHeight(100);
//设置图像的文本环绕样式
picture->SetTextWrappingStyle(TextWrappingStyle::Tight);
//保存结果文档
document->SaveToFile(L"插入图像.docx", FileFormat::Docx2013);
document->Close();
}
Spire.Doc for C++ 使您能够将图像插入Word 文档并使用 DocPicture->SetHorizontalPosition() 和 DocPicture->SetVerticalPosition() 方法设置其位置。详细步骤如下:
#include "Spire.Doc.o.h"
using namespace Spire::Doc;
using namespace Spire::Common;
int main()
{
//创建Document的对象
intrusive_ptr<Document> document = new Document();
//添加一个节
intrusive_ptr<Section> section = document->AddSection();
//向该节添加一个段落
intrusive_ptr<Paragraph> paragraph = section->AddParagraph();
//向段落添加文本并设置格式
intrusive_ptr<TextRange> tr = paragraph->AppendText(L"此示例演示如何在Word文档中的指定位置插入图像。");
tr->GetCharacterFormat()->SetFontName(L"宋体");
paragraph->ApplyStyle(BuiltinStyle::Heading2);
//将图像添加到段落
intrusive_ptr<DocPicture> picture = paragraph->AppendPicture(L"Doc-CPP.png");
//设置图片大小
picture->SetWidth(100);
picture->SetHeight(100);
//设置图像位置
picture->SetHorizontalPosition(180.0F);
picture->SetVerticalPosition(60.0F);
//为图片设置文字环绕样式(注意当文字环绕样式为Inline时位置设置不适用)
picture->SetTextWrappingStyle(TextWrappingStyle::Through);
//保存结果文件
document->SaveToFile(L"在指定位置插入图像.docx", FileFormat::Docx);
document->Close();
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Spreadsheet 7.3.0 已发布。本次更新支持隐藏筛选器的排序项。此外,该版本还成功修复了隐藏列和行的标题栏时只有当前活动工作表生效的问题。详情请阅读以下内容。
新功能:
this.spreadsheet1.HideSortItemInFilter = true;问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Spreadsheet-NET.html
Word 允许用户创建可供其他人录入信息的表单。表单可以从多个对象收集数据或反馈,并且能够保持收集到的内容格式一致。以下是在 Word 文档中创建可填充表单可能需要用到的工具:
Word 中的内容控件是内容容器,用户可以使用它们来创建结构化文档。结构化文档控制内容在文档中出现的位置。Word 2013 中有10种常见的内容控件,本文主要介绍如何使用 Spire.Doc for C++ 创建以下7种内容控件组成的可填充表单:
| 内容控件 | 描述 |
| 纯文本内容控件 | 允许用户输入无格式的文本。 |
| 格式文本内容控件 | 允许用户录入带格式的文本,以及表格、图片、内容控件等其他内容。 |
| 图片内容控件 | 允许用户录入单张图片。 |
| 下拉列表内容控件 | 允许用户从预定义的列表中选择项目。 |
| 组合框内容控件 | 允许用户从预定义的列表中选择项目或自己输入信息。 |
| 复选框内容控件 | 允许用户进行勾选。 |
| 日期选取器内容控件 | 允许用户从日历中选取日期。 |
有两种方法可以将 Spire.Doc for C++ 集成到您的应用程序中。一种方法是通过 NuGet 安装它,另一种方法是从我们的网站下载包并将库复制到您的程序中。通过 NuGet 安装更简单,更推荐使用。您可以通过访问以下链接找到更多详细信息。
如何将 Spire.Doc for C++ 集成到 C++ 程序中
Spire.Doc for C++ 提供的 StructureDocumentTagInline 类用于在段落中为 DrawingML、域等内联级结构创建结构化文档标签。此类下的 SDTProperties 和 SDTContent 属性可以设置对应结构化文档标签的属性和内容。以下是在 Word 文档中创建可填充表单的详细操作步骤:
#include "Spire.Doc.o.h";
using namespace Spire::Doc;
using namespace std;
int main() {
//创建Document的对象
intrusive_ptr<Document> doc = new Document();
//添加一个节
intrusive_ptr<Section> section = doc->AddSection();
//添加一个表格
intrusive_ptr<Table> table = section->AddTable(true);
table->ResetCells(7, 2);
//添加文本到第一列的单元格
intrusive_ptr<Paragraph> paragraph = table->GetRows()->GetItemInRowCollection(0)->GetCells()->GetItemInCellCollection(0)->AddParagraph();
paragraph->AppendText(L"纯文本内容控件");
paragraph = table->GetRows()->GetItemInRowCollection(1)->GetCells()->GetItemInCellCollection(0)->AddParagraph();
paragraph->AppendText(L"格式文本内容控件");
paragraph = table->GetRows()->GetItemInRowCollection(2)->GetCells()->GetItemInCellCollection(0)->AddParagraph();
paragraph->AppendText(L"图片内容控件");
paragraph = table->GetRows()->GetItemInRowCollection(3)->GetCells()->GetItemInCellCollection(0)->AddParagraph();
paragraph->AppendText(L"下拉列表内容控件");
paragraph = table->GetRows()->GetItemInRowCollection(4)->GetCells()->GetItemInCellCollection(0)->AddParagraph();
paragraph->AppendText(L"复选框内容控件");
paragraph = table->GetRows()->GetItemInRowCollection(5)->GetCells()->GetItemInCellCollection(0)->AddParagraph();
paragraph->AppendText(L"组合框内容控件");
paragraph = table->GetRows()->GetItemInRowCollection(6)->GetCells()->GetItemInCellCollection(0)->AddParagraph();
paragraph->AppendText(L"日期选取器内容控件");
//添加纯文本内容控件到单元格(0,1)
paragraph = table->GetRows()->GetItemInRowCollection(0)->GetCells()->GetItemInCellCollection(1)->AddParagraph();
intrusive_ptr<StructureDocumentTagInline> sdt = new StructureDocumentTagInline(doc);
paragraph->GetChildObjects()->Add(sdt);
sdt->GetSDTProperties()->SetSDTType(SdtType::Text);
sdt->GetSDTProperties()->SetAlias(L"纯文本");
sdt->GetSDTProperties()->SetTag(L"纯文本");
sdt->GetSDTProperties()->SetIsShowingPlaceHolder(true);
intrusive_ptr<SdtText> text = new SdtText(true);
text->SetIsMultiline(false);
sdt->GetSDTProperties()->SetControlProperties(text);
intrusive_ptr<TextRange> tr = new TextRange(doc);
tr->SetText(L"单击或点击此处输入文字。");
sdt->GetSDTContent()->GetChildObjects()->Add(tr);
//添加格式文本内容控件到单元格(1,1)
paragraph = table->GetRows()->GetItemInRowCollection(1)->GetCells()->GetItemInCellCollection(1)->AddParagraph();
sdt = new StructureDocumentTagInline(doc);
paragraph->GetChildObjects()->Add(sdt);
sdt->GetSDTProperties()->SetSDTType(SdtType::RichText);
sdt->GetSDTProperties()->SetAlias(L"格式文本");
sdt->GetSDTProperties()->SetTag(L"格式文本");
sdt->GetSDTProperties()->SetIsShowingPlaceHolder(true);
text = new SdtText(true);
text->SetIsMultiline(false);
sdt->GetSDTProperties()->SetControlProperties(text);
tr = new TextRange(doc);
tr->SetText(L"单击或点击此处输入文字。");
sdt->GetSDTContent()->GetChildObjects()->Add(tr);
//添加图片内容控件到单元格(2,1)
paragraph = table->GetRows()->GetItemInRowCollection(2)->GetCells()->GetItemInCellCollection(1)->AddParagraph();
sdt = new StructureDocumentTagInline(doc);
paragraph->GetChildObjects()->Add(sdt);
sdt->GetSDTProperties()->SetSDTType(SdtType::Picture);
sdt->GetSDTProperties()->SetAlias(L"图片");
sdt->GetSDTProperties()->SetTag(L"图片");
intrusive_ptr<SdtPicture> sdtPicture = new SdtPicture();
sdt->GetSDTProperties()->SetControlProperties(sdtPicture);
intrusive_ptr<DocPicture> pic = new DocPicture(doc);
pic->LoadImageSpire(L"C:/Workspace.png");
sdt->GetSDTContent()->GetChildObjects()->Add(pic);
//添加下拉列表内容控件到单元格(3,1)
paragraph = table->GetRows()->GetItemInRowCollection(3)->GetCells()->GetItemInCellCollection(1)->AddParagraph();
sdt = new StructureDocumentTagInline(doc);
sdt->GetSDTProperties()->SetSDTType(SdtType::DropDownList);
sdt->GetSDTProperties()->SetAlias(L"下拉列表");
sdt->GetSDTProperties()->SetTag(L"下拉列表");
paragraph->GetChildObjects()->Add(sdt);
intrusive_ptr<SdtDropDownList> sddl = new SdtDropDownList();
sddl->GetListItems()->Add(new SdtListItem(L"选择一项。", L"1"));
sddl->GetListItems()->Add(new SdtListItem(L"项目 2", L"2"));
sddl->GetListItems()->Add(new SdtListItem(L"项目 3", L"3"));
sddl->GetListItems()->Add(new SdtListItem(L"项目 4", L"4"));
sdt->GetSDTProperties()->SetControlProperties(sddl);
tr = new TextRange(doc);
tr->SetText(sddl->GetListItems()->GetItem(0)->GetDisplayText());
sdt->GetSDTContent()->GetChildObjects()->Add(tr);
//添加两个复选框内容控件到单元格(4,1)
paragraph = table->GetRows()->GetItemInRowCollection(4)->GetCells()->GetItemInCellCollection(1)->AddParagraph();
sdt = new StructureDocumentTagInline(doc);
paragraph->GetChildObjects()->Add(sdt);
sdt->GetSDTProperties()->SetSDTType(SdtType::CheckBox);
intrusive_ptr<SdtCheckBox> scb = new SdtCheckBox();
sdt->GetSDTProperties()->SetControlProperties(scb);
tr = new TextRange(doc);
sdt->GetChildObjects()->Add(tr);
scb->SetChecked(false);
paragraph->AppendText(L"选项 1");
paragraph = table->GetRows()->GetItemInRowCollection(4)->GetCells()->GetItemInCellCollection(1)->AddParagraph();
sdt = new StructureDocumentTagInline(doc);
paragraph->GetChildObjects()->Add(sdt);
sdt->GetSDTProperties()->SetSDTType(SdtType::CheckBox);
scb = new SdtCheckBox();
sdt->GetSDTProperties()->SetControlProperties(scb);
tr = new TextRange(doc);
sdt->GetChildObjects()->Add(tr);
scb->SetChecked(false);
paragraph->AppendText(L"选项 2");
//添加组合框内容控件到单元格(5,1)
paragraph = table->GetRows()->GetItemInRowCollection(5)->GetCells()->GetItemInCellCollection(1)->AddParagraph();
sdt = new StructureDocumentTagInline(doc);
paragraph->GetChildObjects()->Add(sdt);
sdt->GetSDTProperties()->SetSDTType(SdtType::ComboBox);
sdt->GetSDTProperties()->SetAlias(L"组合框");
sdt->GetSDTProperties()->SetTag(L"组合框");
intrusive_ptr<SdtComboBox> cb = new SdtComboBox();
cb->GetListItems()->Add(new SdtListItem(L"选择一项。"));
cb->GetListItems()->Add(new SdtListItem(L"项目 2"));
cb->GetListItems()->Add(new SdtListItem(L"项目 3"));
sdt->GetSDTProperties()->SetControlProperties(cb);
tr = new TextRange(doc);
tr->SetText(cb->GetListItems()->GetItem(0)->GetDisplayText());
sdt->GetSDTContent()->GetChildObjects()->Add(tr);
//添加日期选取器内容控件到单元格(6,1)
paragraph = table->GetRows()->GetItemInRowCollection(6)->GetCells()->GetItemInCellCollection(1)->AddParagraph();
sdt = new StructureDocumentTagInline(doc);
paragraph->GetChildObjects()->Add(sdt);
sdt->GetSDTProperties()->SetSDTType(SdtType::DatePicker);
sdt->GetSDTProperties()->SetAlias(L"日期选取器");
sdt->GetSDTProperties()->SetTag(L"日期选取器");
intrusive_ptr<SdtDate> date = new SdtDate();
date->SetCalendarType(CalendarType::Default);
date->SetDateFormatSpire(L"yyyy.MM.dd");
date->SetFullDate(DateTime::GetNow());
sdt->GetSDTProperties()->SetControlProperties(date);
tr = new TextRange(doc);
tr->SetText(L"单击或点击此处输入日期。");
sdt->GetSDTContent()->GetChildObjects()->Add(tr);
//设置仅允许用户编辑表单域
doc->Protect(ProtectionType::AllowOnlyFormFields, L"password");
//保存文档
doc->SaveToFile(L"Output/表单.docx", FileFormat::Docx2013);
doc->Close();
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
将 Excel 文件转换为 HTML 文件可以方便我们将电子表格嵌入到网站中,同时允许浏览者直接在浏览器中在线查看电子表格内容,而不需要下载文件或是打开 Excel 进行查看。本文将介绍如何使用 Spire.XLS for C++ 将 Excel 工作簿或指定工作表转换为 HTML 文件。
有两种方法可以将 Spire.XLS for C++ 集成到您的应用程序中。一种方法是通过 NuGet 安装它,另一种方法是从我们的网站下载包并将库复制到您的程序中。通过 NuGet 安装更简单,更推荐使用。您可以通过访问以下链接找到更多详细信息。
如何将 Spire.XLS for C++ 集成到 C++ 程序中
Spire.XLS for C++ 提供的 Workbook->SaveToHtml() 方法允许将整个工作簿转换为一个 HTML 文件。以下是详细操作步骤:
#include "Spire.Xls.o.h"
using namespace Spire::Xls;
int main()
{
//创建Workbook的对象
intrusive_ptr<Workbook> workbook = new Workbook();
//载入Excel文件
workbook->LoadFromFile(L"C:/销售发票跟踪.xlsx");
//将整个工作簿保存为HTML文件
workbook->SaveToHtml(L"Output/HTML.html");
workbook->Dispose();
}
在转换工作表为 HTML 文件时,我们可以使用 HTMLOptions->SetImageEmbedded() 方法将工作表中的图片嵌入到 HTML 代码中。以下是详细操作步骤:
#include "Spire.Xls.o.h"
using namespace Spire::Xls;
int main()
{
//创建Workbook的对象
intrusive_ptr<Workbook> workbook = new Workbook();
//载入Excel文件
workbook->LoadFromFile(L"C:/销售发票跟踪.xlsx");
//获取第一个工作表
intrusive_ptr<Worksheet> sheet = dynamic_pointer_cast<Worksheet>(workbook->GetWorksheets()->Get(0));
//设置允许嵌入图片
intrusive_ptr<HTMLOptions> options = new HTMLOptions();
options->SetImageEmbedded(true);
//将工作表保存为HTML文件
sheet->SaveToHtml(L"Output/HTML.html", options);
workbook->Dispose();
}
Spire.XLS for C++ 中的 Worksheet->SaveToHtml(Stream* stream, HTMLOptions* saveOption) 方法允许将工作表保存为 HTML 流。以下是详细操作步骤:
#include "Spire.Xls.o.h"
using namespace Spire::Xls;
int main()
{
//创建Workbook的对象
intrusive_ptr<Workbook> workbook = new Workbook();
//载入Excel文件
workbook->LoadFromFile(L"C:/销售发票跟踪.xlsx");
//获取第一个工作表
intrusive_ptr<Worksheet> sheet = dynamic_pointer_cast<Worksheet>(workbook->GetWorksheets()->Get(0));
//设置允许嵌入图片
intrusive_ptr<<HTMLOptions> options = new HTMLOptions();
options->SetImageEmbedded(true);
//创建流
intrusive_ptr<Stream> stream = new Stream();
//将工作表保存为HTML流
sheet->SaveToHtml(stream, options);
workbook->Dispose();
stream->Save(L"Output/HTML流.html");
}如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Excel 是创建和管理电子表格的绝佳工具,但分享电子表格时,Excel 文件格式可能不是最佳选择。制作 Excel 表格之后,我们可以将其转换为 PDF 文件,这样可以在保留表格格式的同时,使其在各种不同的设备上展示出同样的效果。此外,PDF 有更多的安全选项,我们可以加密转换出的 PDF 文件,防止其被随意篡改。
本文将介绍如何使用 Spire.XLS for C++ 通过程序将 Excel 工作簿转换为 PDF 文件或是将单个 Excel 工作表转换为 PDF 文件。
有两种方法可以将 Spire.XLS for C++ 集成到您的应用程序中。一种方法是通过 NuGet 安装它,另一种方法是从我们的网站下载包并将库复制到您的程序中。通过 NuGet 安装更简单,更推荐使用。您可以通过访问以下链接找到更多详细信息。
在 C++ 应用程序中集成 Spire.XLS for C++
Spire.XLS for C++ 中的 Workbook->SaveToFile(LPCWSTR_S fileName, FileFormat fileFormat) 方法可以将整个 Excel 工作簿转换其他文件格式,如 PDF、HTML、CSV、XPS等。此外,ConverterSetting 可以对转换选项进行设置,如转换时自动调整单元格行高和列宽。以下是将 Excel 工作簿转换为 PDF 文件的操作步骤:
#include "Spire.Xls.o.h"
using namespace Spire::Xls;
int main()
{
//创建Workbook的对象
intrusive_ptr<Workbook> workbook = new Workbook();
//载入Excel文件
workbook->LoadFromFile(L"C:/家庭每月预算.xlsx");
//设置转换时工作表适应页面
workbook->GetConverterSetting()->SetSheetFitToPage(true);
//将Excel工作簿转换为PDF文件
workbook->SaveToFile(L"Output/Excel转PDF.pdf", FileFormat::PDF);
workbook->Dispose();
}
在导出指定工作表为 PDF 时,我们需要先用 Workbook->GetWorksheets()->Get(index) 方法获取该工作表,再用 Worksheet->SaveToPdf(LPCWSTR_S fileName) 方法将其保存为 PDF 文件。以下是详细操作步骤:
#include "Spire.Xls.o.h"
using namespace Spire::Xls;
int main()
{
//创建Workbook的对象
intrusive_ptr<Workbook> workbook = new Workbook();
//载入Excel文件
workbook->LoadFromFile(L"C:/家庭每月预算.xlsx");
//设置转换时工作表适应页面
workbook->GetConverterSetting()->SetSheetFitToPage(true);
//获取指定工作表
intrusive_ptr<Worksheet> sheet = dynamic_pointer_cast<Worksheet>(workbook->GetWorksheets()->Get(3));
//将该工作表保存为PDF文件
sheet->SaveToPdf(L"Excel转PDF.pdf");
workbook->Dispose();
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Office for Java 8.3.6 已发布。在该版本中,Spire.PDF for Java 支持 PDF 打印缩放功能;Spire.Doc for Java 支持修改修订时间的功能;Spire.XLS for Java 支持将 Excel 转换为独立的 HTML 文件,以及替换单元格内部分文本内容;Spire.Presentation for Java 支持 DPT 和 DPS 文件格式。此外,改版本还成功修复了大量已知问题。详情请阅读以下内容。
获取 Spire.Office for Java 8.3.6请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
新功能:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String dateString = "2023/3/1 00:00:00";
Date date = formatter.parse(dateString);
revison.setDateTime(date);问题修复:
新功能:
pdfDocument.getPrintSettings().selectSinglePageLayout
(PdfSinglePageScalingMode.Custom_Sacle, true, customScaling);问题修复:
新功能:
Workbook wb = new Workbook();
wb.loadFromFile("data/mytest.xlsx");
HTMLOptions.Default.isStandAloneHtmlFile(true);
wb.saveToFile("result.html", FileFormat.HTML);Workbook wb = new Workbook();
wb.loadFromFile("data/mytest.xlsx");
FileOutputStream fileStream = new FileOutputStream("output/saveStream_result.html");
wb.saveToStream(fileStream, FileFormat.HTML);
fileStream.close();PivotTable table = (PivotTable)worksheet.getPivotTables().get(0);
PivotConditionalFormatCollection pcfs = table.getPivotConditionalFormats();
PivotConditionalFormat pc = pcfs.addPivotConditionalFormat(table.getColumnFields().get(0));
//PivotConditionalFormat pc = pcfs.addPivotConditionalFormat(table.getRowFields().get(0));
//PivotConditionalFormat pc = pcfs.addPivotConditionalFormat(table.getDataFields().get(0));
//PivotConditionalFormat pc = pcfs.addPivotConditionalFormat(table.getPageFields().get(0));
IConditionalFormat cf = pc.addCondition();
cf.setFormatType(ConditionalFormatType.ContainsBlanks);
cf.setFillPattern(ExcelPatternType.Solid);
cf.setBackColor(Color.Red);sheet.getCellList().get(0).textPartReplace("Office", "Spire");问题修复:
新功能:
Presentation presentation = new Presentation();
presentation.loadFromFile("sample.dps", FileFormat.DPS);
presentation.saveToFile("result.dpt", FileFormat.DPT);问题修复:
Spire.Doc for Java 11.3.11 已发布。本次更新新增支持修改修订的时间的功能。同时,此版本增强了 Word 到 PDF 的转换。此外,该版本还修复了许多已知问题,如:修复了获取文档页数不正确的问题。详情请阅读以下内容。
新功能:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String dateString = "2023/3/1 00:00:00";
Date date = formatter.parse(dateString);
revison.setDateTime(date);问题修复:
Microsoft Word 中的查找和替换功能是编辑文档时必不可少的工具。它使您能够在 Word 文档中快速找到特定的单词或短语,并可以一次替换它的所有实例。这在您需要更新信息或更正大型 Word 文档中拼写错误的单词的情况下尤其有用。在本文中,您将学习如何使用 Spire.Doc for C++ 在 C++ 中查找和替换 Word 文档中的文本。
有两种方法可以将 Spire.Doc for C++ 集成到您的应用程序中。一种方法是通过 NuGet 安装它,另一种方法是从我们的网站下载包并将库复制到您的程序中。通过 NuGet 安装更简单,更推荐使用。您可以通过访问以下链接找到更多详细信息。
如何将 Spire.Doc for C++ 集成到 C++ 程序中
您可以使用 Document->Replace() 方法轻松地找到一个文本并将其所有实例替换为另一个文本。具体步骤如下:
#include "Spire.Doc.o.h"
using namespace Spire::Doc;
using namespace std;
int main()
{
//创建Document的对象
intrusive_ptr<Documentr> document = new Document();
//加载 Word 文档
document->LoadFromFile(L"Input.docx");
//查找特定文本并将其所有实例替换为另一个文本
document->Replace(L"Spire.Doc", L"Eiceblue", false, true);
//保存结果文档
document->SaveToFile(L"替换所有实例.docx", FileFormat::Docx2013);
document->Close();
}
Spire.Doc for C++ 提供了 Document->SetReplaceFirst() 方法,使您可以将替换模式从替换所有实例更改为替换第一个实例。 以下步骤说明了如何查找文本并替换其第一个实例:
#include "Spire.Doc.o.h"
using namespace Spire::Doc;
using namespace std;
int main()
{
//初始化 Document 类的一个实例
intrusive_ptr<document> document = new Document();
//加载 Word 文档
document->LoadFromFile(L"Input.docx");
//更改替换模式以替换第一个匹配项
document->SetReplaceFirst(true);
//用另一个文本替换文本的第一个实例
document->Replace(L"Spire.Doc", L"Eiceblue", false, true);
//保存结果文档
document->SaveToFile(L"替换第一个实例.docx", FileFormat::Docx2013);
document->Close();
}
您可以使用 Document->Replace() 方法将与正则表达式匹配的文本替换为新文本,并将 Regex 实例和新文本作为参数传递给该方法。具体步骤如下:
#include "Spire.Doc.o.h"
using namespace Spire::Doc;
using namespace std;
int main()
{
//初始化 Document 类的一个实例
intrusive_ptr<Document> doc = new Document();
//加载 Word 文档
doc->LoadFromFile(L"示例文档.docx");
//创建一个正则表达式以匹配以 # 开头的文本
intrusive_ptr <Regex> regex = new Regex(L"\\#\\w+\\b");
//查找与正则表达式匹配的文本并将其替换为另一个文本
doc->Replace(regex, L"显示器");
//保存结果文档
doc->SaveToFile(L"替换为正则表达式.docx", FileFormat::Docx2013);
doc->Close();
}
Spire.Doc for C++ 没有提供用图像替换文本的直接方法,但您可以通过在文本位置插入图像然后从文档中删除文本来实现此操作。详细步骤如下:
#include "Spire.Doc.o.h"
using namespace Spire::Doc;
using namespace std;
int main()
{
//初始化 Document 类的一个实例
intrusive_ptr<Document> doc = new Document();
//加载 Word 文档
doc->LoadFromFile(L"Input.docx");
//在文档中查找一段文本,并将查找到的结果放入一个向量中
vector<intrusive_ptr<TextSelection>< selections = doc->FindAllString(L"Spire.Doc", true, true);
int index = 0;
intrusive_ptr<TextRange> range = nullptr;
//遍历向量中找到的文本
for (auto selection : selections)
{
//加载图像
DocPicture* pic = new DocPicture(doc);
pic->LoadImageSpire(L"img.jpg");
//将找到的文本作为单个文本范围
range = selection->GetAsOneRange();
//获取其所有者段落中文本范围的索引
index = range->GetOwnerParagraph()->GetChildObjects()->IndexOf(range);
//在索引处插入图像
range->GetOwnerParagraph()->GetChildObjects()->Insert(index, pic);
//删除文本范围
range->GetOwnerParagraph()->GetChildObjects()->Remove(range);
}
//保存结果文档
doc->SaveToFile(L"替换为图片.docx", FileFormat::Docx2013);
doc->Close();
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Presentation for Java 8.3.2 已发布。改版本新增支持 DPT 和DPS 文件格式。本次更新还增强了 HTML 到 PPT 及 PPT 到图片的转换。此外,一些已知问题也在该版本中被成功修复,如加载PPT文档时程序抛异常 Unknown file format 的问题。详情请阅读以下内容。
新功能:
Presentation presentation = new Presentation();
presentation.loadFromFile("sample.dps", FileFormat.DPS);
presentation.saveToFile("result.dpt", FileFormat.DPT);问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-JAVA.html