Spire.Doc for Java 11.5.5 已发布。该版本增强了 Word 到 PDF 和Word 到OFD的转换。此外,本次更新还修复了许多已知问题,如修复了加载文档时程序报错"Attempted to read past the end of the stream" 的问题。详情请阅读以下内容。
问题修复:
Spire.Office 8.5.3 已发布。在该版本中,Spire.XLS 新增支持 ISO.CEILING 和 WORKDAY.INTL 函数,以及 WPS 中的 EVALUATE() 函数;Spire.Doc 支持了添加图表的功能;Spire.PDF 优化了压缩 PDF 文档的功能。此外,本次更新还成功修复了大量已知问题。详情请阅读以下内容。
该版本涵盖了最新版的 Spire.Doc,Spire.PDF,Spire.XLS,Spire.Email,Spire.DocViewer, Spire.PDFViewer,Spire.Presentation,Spire.Spreadsheet, Spire.OfficeViewer, Spire.DocViewer, Spire.Barcode, Spire.DataExport。
版本信息如下:
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
新功能:
//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Column chart.");
//创建一个新节以附加柱形图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Column, 500, 300);
//清除图表的系列数据,以一个干净的图表开始。
Chart chart = shape.Chart;
chart.Series.Clear();
//将自定义系列添加到图表中,其中X轴为类别,Y轴为相应的大数值。
chart.Series.Add("Test Series",
new[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
new double[] { 1900000, 850000, 2100000, 600000, 1500000 });
//将Y轴刻度标签的数字格式设置为使用逗号对数字进行分组。
chart.AxisY.NumberFormat.FormatCode = "#,##0";
//保存结果文档
document.SaveToFile("AppendColumnChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Bubble chart.");
//创建一个新段落并打开气泡图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Bubble, 500, 300);
//清除字符的序列数据,以一个干净的图表开始
Chart chart = shape.Chart;
chart.Series.Clear();
// 添加带有X/Y坐标和每个气泡直径的自定义系列
ChartSeries series = chart.Series.Add("Test Series",
new[] { 2.9, 3.5, 1.1, 4.0, 4.0 },
new[] { 1.9, 8.5, 2.1, 6.0, 1.5 },
new[] { 9.0, 4.5, 2.5, 8.0, 5.0 });
//保存doc文件
document.SaveToFile("AppendBubbleChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Line chart.");
//创建一个新段落以附加折线图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Line, 500, 300);
//清除折线图的系列数据以从干净的图表开始
Chart chart = shape.Chart;
ChartTitle title = chart.Title;
title.Text = "My Chart";
ChartSeriesCollection seriesColl = chart.Series;
seriesColl.Clear();
//在图表内设置新数据
string[] categories = { "C1", "C2", "C3", "C4", "C5", "C6" };
seriesColl.Add("AW Series 1", categories, new double[] { 1, 2, 2.5, 4, 5, 6 });
seriesColl.Add("AW Series 2", categories, new double[] { 2, 3, 3.5, 6, 6.5, 7 });
//保存doc文件
document.SaveToFile("AppendLineChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Pie chart.");
//创建一个新段落以附加饼图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Pie, 500, 300);
Chart chart = shape.Chart;
//插入一个自定义图表系列,其中包含每个扇区的类别名称及其频率值。
ChartSeries series = chart.Series.Add("Test Series",
new[] { "Word", "PDF", "Excel" },
new[] { 2.7, 3.2, 0.8 });
//保存到docx文件。
document.SaveToFile("AppendPieChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Scatter chart.");
//创建一个新段落以附加散点图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Scatter, 450, 300);
Chart chart = shape.Chart;
//清除图表的系列数据,以一个干净的图表开始
chart.Series.Clear();
//插入五个点的X/Y坐标系列
chart.Series.Add("Scatter chart",
new[] { 1.0, 2.0, 3.0, 4.0, 5.0 },
new[] { 1.0, 20.0, 40.0, 80.0, 160.0 });
//保存到docx文件
document.SaveToFile("AppendScatterChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Surface3D chart.");
//创建新段落以附加曲面三维图表
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Surface3D, 500, 300);
//清除其系列数据,以一个干净的图表开始
Chart chart = shape.Chart;
chart.Series.Clear();
chart.Title.Text = "My chart";
//添加三个系列
chart.Series.Add("Series 1",
new string[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
new double[] { 1900000, 850000, 2100000, 600000, 1500000 });
chart.Series.Add("Series 2",
new string[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
new double[] { 900000, 50000, 1100000, 400000, 2500000 });
chart.Series.Add("Series 3",
new string[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
new double[] { 500000, 820000, 1500000, 400000, 100000 });
//保存到docx文件.
document.SaveToFile("AppendSurface3DChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Bar chart.");
//创建一个新段落以附加条形图
Paragraph newPara = section.AddParagraph();
ShapeObject chartShape = newPara.AppendChart(ChartType.Bar, 400, 300);
Chart chart = chartShape.Chart;
//使用“标题”属性为条形图提供一个标题,该标题显示在图表区域的顶部中心。
ChartTitle title = chart.Title;
title.Text = "My Chart";
//将“Show”属性设置为“true”以使标题可见。
title.Show = true;
//将“Overlay”属性设置为“true”。允许其他图表元素与标题重叠,从而给它们更多的空间
title.Overlay = true;
//保存到docx文件
document.SaveToFile("AppendBarChart.docx", FileFormat.Docx);Document document = new Document();
Section section = document.AddSection();
string svgFile = "sample.svg";
Paragraph para = section.AddParagraph();
DocPicture svgPicture = para.AppendPicture(svgFile);
svgPicture.Width = 200;
svgPicture.Height = 200;
String DocxResult = "Result-AddSvg.docx";
document.SaveToFile(DocxResult, FileFormat.Docx2016);Document doc = new Document();
doc.LoadFromFile(https://cdn.e-iceblue.cn/inputFile, FileFormat.Docx);
System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
printDialog.PrinterSettings.PrintToFile = true;
printDialog.PrinterSettings.PrintFileName = "sample-new-4.xps";
doc.PrintDialog = printDialog;
doc.PrintMultipageToOneSheet(PagesPreSheet.FourPages, true);Document doc = new Document();
doc.LoadFromFile(https://cdn.e-iceblue.cn/inputFile, FileFormat.Docx);
FixedLayoutDocument layoutDoc = new FixedLayoutDocument(doc);
// 访问第一页的行并打印到控制台。
FixedLayoutLine line = layoutDoc.Pages[0].Columns[0].Lines[0];
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Line: " + line.Text);
//使用渲染的行,可以返回文档对象模型中的原始段落。
Paragraph para = line.Paragraph;
stringBuilder.AppendLine("Paragraph text: " + para.Text);
// 以纯文本格式(包括页眉和页脚)检索第一页上显示的所有文本。
string pageText = layoutDoc.Pages[0].Text;
stringBuilder.AppendLine(pageText);
// 循环遍历文档中的每一页,并打印每页上显示的行数。
foreach (FixedLayoutPage page in layoutDoc.Pages)
{
LayoutCollection lines = page.GetChildEntities(LayoutElementType.Line, true);
stringBuilder.AppendLine("Page " + page.PageIndex + " has " + lines.Count + " lines.");
}
// 此方法为任何给定节点提供布局实体的反向查找
// (页眉和页脚中的管路和节点除外)。
stringBuilder.AppendLine("The lines of the first paragraph:");
foreach (FixedLayoutLine paragraphLine in layoutDoc.GetLayoutEntitiesOfNode(
((Section)doc.FirstChild).Body.Paragraphs[0]))
{
stringBuilder.AppendLine(paragraphLine.Text.Trim());
stringBuilder.AppendLine(paragraphLine.Rectangle.ToString());
}
File.WriteAllText("page.txt", stringBuilder.ToString()); 新功能:
Workbook workbook = new Workbook();
workbook.Worksheets[0].Range["A1"].Formula = "ISO.CEILING(12.69,2)";
workbook.CalculateAllValue();
workbook.SaveToFile("result.xlsx",ExcelVersion.Version2016);Workbook workbook = new Workbook();
workbook.Worksheets[0].Range["A1"].Formula = "=WORKDAY.INTL(DATE(2023,3,17),25,1,DATE(2023,3,20))";
workbook.CalculateAllValue();
workbook.SaveToFile("result.xlsx",ExcelVersion.Version2016);问题修复:
新功能:
PdfCompressor compressor = new PdfCompressor("input.pdf");
compressor.Options.TextCompressionOptions.UnembedFonts = true;
compressor.Options.ImageCompressionOptions.CompressImage = true;
compressor.Options.ImageCompressionOptions.ResizeImages = true;
compressor.Options.ImageCompressionOptions.ImageQuality = ImageQuality.Low;
compressor.CompressToFile("output.pdf");问题修复:
问题修复:
Excel 中的数据验证控制可以将哪些类型的信息输入到单元格中。使用它,您可以仅将特定的数据类型(如数字或日期)限制在单元格中,或者将数字限制在特定范围内,并将文本限制在特定长度内。此外,它还允许您在下拉菜单中显示预定义值的列表,供用户选择。在本文中,您将学习如何使用 Spire.XLS for C++ 在 Excel 中应用或删除数据验证。
有两种方法可以将 Spire.XLS for C++ 集成到您的应用程序中。一种方法是通过 NuGet 安装它,另一种方法是从我们的网站下载包并将库复制到您的程序中。通过 NuGet 安装更简单,更推荐使用。您可以通过访问以下链接找到更多详细信息。
如何将 Spire.XLS for C++ 集成到 C++ 程序中
Spire.XLS for C++ 允许您为数字、日期、文本值、列表等创建验证规则。以下是将不同数据验证类型应用于 Excel 中指定单元格的步骤。
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
int main() {
//指定输出文件
std::wstring outputFile = L"数据验证.xlsx";
//创建Workbook对象
intrusive_ptr<Workbook> workbook = new Workbook();
//获取指定的工作表
intrusive_ptr<Worksheet> sheet = dynamic_pointer_cast<Worksheet>(workbook->GetWorksheets()->Get(0));
//在指定的单元格中插入文本
dynamic_pointer_cast<CellRange>(sheet->GetRange(L"B2"))->SetText(L"编号验证: ");
dynamic_pointer_cast<CellRange>(sheet->GetRange(L"B4"))->SetText(L"日期验证: ");
dynamic_pointer_cast<CellRange>(sheet->GetRange(L"B6"))->SetText(L"文本长度验证: ");
dynamic_pointer_cast<CellRange>(sheet->GetRange(L"B8"))->SetText(L"列表验证: ");
dynamic_pointer_cast<CellRange>(sheet->GetRange(L"B10"))->SetText(L"时间验证: ");
//将数字验证添加到C2
intrusive_ptr<CellRange> rangeNumber = dynamic_pointer_cast<CellRange>(sheet->GetRange(L"C2"));
rangeNumber->GetDataValidation()->SetAllowType(CellDataType::Decimal);
rangeNumber->GetDataValidation()->SetCompareOperator(ValidationComparisonOperator::Between);
rangeNumber->GetDataValidation()->SetFormula1(L"3");
rangeNumber->GetDataValidation()->SetFormula2(L"6");
rangeNumber->GetDataValidation()->SetInputMessage(L"输入一个介于1和10之间的数字");
rangeNumber->GetDataValidation()->SetErrorMessage(L"请输入正确的数字!");
rangeNumber->GetDataValidation()->SetShowError(true);
rangeNumber->GetDataValidation()->SetAlertStyle(AlertStyleType::Warning);
rangeNumber->GetStyle()->SetKnownColor(ExcelColors::Gray25Percent);
//将日期验证添加到C4
intrusive_ptr<CellRange> rangeDate = dynamic_pointer_cast<CellRange>(sheet->GetRange(L"C4"));
rangeDate->GetDataValidation()->SetAllowType(CellDataType::Date);
rangeDate->GetDataValidation()->SetCompareOperator(ValidationComparisonOperator::Between);
rangeDate->GetDataValidation()->SetFormula1(L"1/1/2021");
rangeDate->GetDataValidation()->SetFormula2(L"12/31/2021");
rangeDate->GetDataValidation()->SetInputMessage(L"输入2021年1月1日至2021年12月31日之间的日期");
rangeDate->GetStyle()->SetKnownColor(ExcelColors::Gray25Percent);
//将文本长度验证添加到C6
intrusive_ptr<CellRange> rangeTextLength = dynamic_pointer_cast<CellRange>(sheet->GetRange(L"C6"));
rangeTextLength->GetDataValidation()->SetAllowType(CellDataType::TextLength);
rangeTextLength->GetDataValidation()->SetCompareOperator(ValidationComparisonOperator::LessOrEqual);
rangeTextLength->GetDataValidation()->SetFormula1(L"5");
rangeTextLength->GetDataValidation()->SetErrorMessage(L"请输入有效字符串!");
rangeTextLength->GetDataValidation()->SetShowError(true);
rangeTextLength->GetDataValidation()->SetAlertStyle(AlertStyleType::Stop);
rangeTextLength->GetStyle()->SetKnownColor(ExcelColors::Gray25Percent);
//对C8应用列表验证
intrusive_ptr<CellRange> rangeList = dynamic_pointer_cast<CellRange>(sheet->GetRange(L"C8"));
std::vector<LPCWSTR_S> files = { L"美国", L"加拿大", L"英国" };
rangeList->GetDataValidation()->SetValues(files);
rangeList->GetDataValidation()->SetIsSuppressDropDownArrow(false);
rangeList->GetDataValidation()->SetInputMessage(L"从列表中选择一个项目");
rangeList->GetStyle()->SetKnownColor(ExcelColors::Gray25Percent);
//对C10应用时间验证
intrusive_ptr<CellRange> rangeTime = dynamic_pointer_cast<CellRange>(sheet->GetRange(L"C10"));
rangeTime->GetDataValidation()->SetAllowType(CellDataType::Time);
rangeTime->GetDataValidation()->SetCompareOperator(ValidationComparisonOperator::Between);
rangeTime->GetDataValidation()->SetFormula1(L"9:00");
rangeTime->GetDataValidation()->SetFormula2(L"12:00");
rangeTime->GetDataValidation()->SetInputMessage(L"输入一个介于9:00和12:00之间的时间");
rangeTime->GetStyle()->SetKnownColor(ExcelColors::Gray25Percent);
//自动调整列2的宽度
sheet->AutoFitColumn(2);
//设置列3的宽度
sheet->GetColumns()->GetItem(2)->SetColumnWidth(20);
//保存结果文档
workbook->SaveToFile(outputFile.c_str(), ExcelVersion::Version2016);
workbook->Dispose();
}
要删除应用于单元格的数据验证,Spire.XLS for C++ 提供了 Worksheet->GetDVTable()->Remove() 方法。详细步骤如下。
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
int main() {
//指定输入和输出文件
std::wstring inputFile = L"数据验证.xlsx";
std::wstring outputFile = L"删除数据验证.xlsx";
//创建Workbook对象
intrusive_ptr<Workbook> workbook = new Workbook();
//加载Excel文档示例
workbook->LoadFromFile(inputFile.c_str());
//获取指定的工作表
intrusive_ptr<Worksheet> sheet = dynamic_pointer_cast<Worksheet>(workbook->GetWorksheets()->Get(0));
//创建一个矩形数组,用于定位工作表中的区域
std::vector<intrusive_ptr<Spire::Common::Rectangle>> rectangles(1);
//为数组的第一个元素赋值,并指定矩形单元格范围
rectangles[0] = Spire::Common::Rectangle::FromLTRB(0, 0, 2, 9);
//删除由矩形表示的范围内的验证
sheet->GetDVTable()->Remove(rectangles);
//保存结果文档
workbook->SaveToFile(outputFile.c_str(), ExcelVersion::Version2016);
workbook->Dispose();
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.PDF for Java 9.5.6 已发布。本次更新增强了OFD到PDF的转换。此外,该版本还修复了一些已知问题,如:修复了填充单元格时,文字被裁减的问题。详情请阅读以下内容。
问题修复:
Spire.PDF 9.5.4 已发布。本次更新优化了压缩 PDF 文档的功能。该版本还增强了 PDF 到 Word、OFD 以及图片的转换功能。此外,许多已知问题也在本次更新中被成功修复,如高亮文本失败的问题。详情请阅读以下内容。
新功能:
PdfCompressor compressor = new PdfCompressor("input.pdf");
compressor.Options.TextCompressionOptions.UnembedFonts = true;
compressor.Options.ImageCompressionOptions.CompressImage = true;
compressor.Options.ImageCompressionOptions.ResizeImages = true;
compressor.Options.ImageCompressionOptions.ImageQuality = ImageQuality.Low;
compressor.CompressToFile("output.pdf");问题修复:
Spire.Email 6.5.7 已发布。该版本修复了在NetFramework应用程序中使用时,无法连接到Imap服务器和Pop3服务器的问题。详情请阅读以下内容。
问题修复:
PowerPoint 是一种流行的格式,用于创建演示文稿、培训材料、业务报告等。然而,它也有一些缺点,例如不够安全,或者在不同的设备/软件上可能存在兼容性问题。而 XPS,也称为 XML 纸张规范,是一种更安全、更兼容的文件格式,适用于高质量打印和快速传输。因此,许多人可能会选择将 PowerPoint 文件转换为 XPS 格式。在本文中,您将学习如何使用 Spire.Presentation for C++ 以编程方式将 PowerPoint 演示文稿转换为 XPS。
有两种方法可以将 Spire.Presentation for C++ 集成到您的应用程序中。一种方法是通过 NuGet 安装它,另一种方法是从我们的网站下载包并将库复制到您的程序中。通过 NuGet 安装更简单,更推荐使用。您可以通过访问以下链接找到更多详细信息。
如何将 Spire.Presentation for C++ 集成到 C++ 程序中
使用 Spire.Presentation for C++ 将 PowerPoint 演示文稿转换为 XPS 文件相当简单。您只需要加载一个 PowerPoint 文档示例,然后使用 Workbook->SaveToFile(LPCWSTR_S fileName, FileFormat::XPS) 方法将其保存为 XPS 格式。以下是详细的步骤。
#include "Spire.Presentation.o.h"
using namespace std;
using namespace Spire::Presentation;
int main()
{
//指定输入和输出文件路径
std::wstring inputFile = L"示例文档.pptx";
std::wstring outputFile = L"ToXPS.xps";
//创建Presentation实例
intrusive_ptr<Presentation> presentation = new Presentation();
//加载PowerPoint文档
presentation->LoadFromFile(inputFile.c_str());
//将文档保存为XPS
presentation->SaveToFile(outputFile.c_str(), FileFormat::XPS);
presentation->Dispose();
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
当将包含大量媒体文件和图像的 PowerPoint 文档发送给他人进行文本校对时,您可能会发现由于文件大小太大,传输速度相当慢。在这种情况下,最好先将 PowerPoint 中的文本提取到 MS Word 或记事本中,然后只发送文本内容。此外,还可以对提取的文本内容进行存档或备份,以备将来参考。在本文中,您将学习如何使用 Spire.Presentation for .NET 在 PowerPoint 演示文稿中提取文本。
首先,您需要添加 Spire.Presentation for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。
PM> Install-Package Spire.Presentation为了便于在 PowerPoint 文档中共享或传递文本信息,有时需要进行文本提取操作。以下是从所有演示文稿幻灯片中提取文本并保存在 TXT 文件中的步骤。
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Converter.Equation.Word;
using System;
using System.IO;
using System.Text;
namespace ExtractText
{
class Program
{
static void Main(string[] args)
{
//初始化Presentation类的实例
Presentation presentation = new Presentation();
//载PowerPoint文档示例
presentation.LoadFromFile("呼吁反虐待动物立法.pptx");
//创建StringBuilder实例
StringBuilder sb = new StringBuilder();
//遍历文档中的每张幻灯片
foreach (ISlide slide in presentation.Slides)
{
//遍历每张幻灯片中的每个形状
foreach (IShape shape in slide.Shapes)
{
//检查形状是否为IAutoShape类型
if (shape is IAutoShape)
{
//以每种形状遍历所有段落
foreach (TextParagraph tp in (shape as IAutoShape).TextFrame.Paragraphs)
{
//提取文本并保存到StringBuilder实例
sb.AppendLine(tp.Text);
}
}
}
}
//创建一个新的txt文件以保存提取的文本
File.WriteAllText("提取文本.txt", sb.ToString());
presentation.Dispose();
}
}
}Imports Spire.Presentation
Imports Spire.Presentation.Charts
Imports Spire.Presentation.Converter.Equation.Word
Imports System.IO
Imports System.Text
Namespace ExtractText
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'初始化Presentation类的实例
Dim presentation As Presentation = New Presentation()
'载PowerPoint文档示例
presentation.LoadFromFile("呼吁反虐待动物立法.pptx")
'创建StringBuilder实例
Dim sb As StringBuilder = New StringBuilder()
'遍历文档中的每张幻灯片
For Each slide As ISlide In presentation.Slides
'遍历每张幻灯片中的每个形状
For Each shape As IShape In slide.Shapes
'检查形状是否为IAutoShape类型
If TypeOf shape Is IAutoShape Then
'以每种形状遍历所有段落
For Each tp As TextParagraph In TryCast(shape, IAutoShape).TextFrame.Paragraphs
'提取文本并保存到StringBuilder实例
sb.AppendLine(tp.Text)
Next
End If
Next
Next
'创建一个新的txt文件以保存提取的文本
Call File.WriteAllText("提取文本.txt", sb.ToString())
presentation.Dispose()
End Sub
End Class
End Namespace
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.PDF for Android via Java 9.5.1 已发布。本次更新修复了添加新的自定义属性后会丢失已有的自定义属性的问题。详情请阅读以下内容。
问题修复:
https://www.e-iceblue.cn/Downloads/pdf-for-android-via-java.html
Spire.Doc 11.5.6已发布。本次更新支持了添加图表的功能和支持了添加SVG文档的功能。此外,该版本也支持打印多页到一页的功能,以及支持了操作页面的功能,比如获取页面的内容以及内容的坐标。详情请阅读以下内容。
新功能:
//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Column chart.");
//创建一个新节以附加柱形图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Column, 500, 300);
//清除图表的系列数据,以一个干净的图表开始。
Chart chart = shape.Chart;
chart.Series.Clear();
//将自定义系列添加到图表中,其中X轴为类别,Y轴为相应的大数值。
chart.Series.Add("Test Series",
new[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
new double[] { 1900000, 850000, 2100000, 600000, 1500000 });
//将Y轴刻度标签的数字格式设置为使用逗号对数字进行分组。
chart.AxisY.NumberFormat.FormatCode = "#,##0";
//保存结果文档
document.SaveToFile("AppendColumnChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Bubble chart.");
//创建一个新段落并打开气泡图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Bubble, 500, 300);
//清除字符的序列数据,以一个干净的图表开始
Chart chart = shape.Chart;
chart.Series.Clear();
// 添加带有X/Y坐标和每个气泡直径的自定义系列
ChartSeries series = chart.Series.Add("Test Series",
new[] { 2.9, 3.5, 1.1, 4.0, 4.0 },
new[] { 1.9, 8.5, 2.1, 6.0, 1.5 },
new[] { 9.0, 4.5, 2.5, 8.0, 5.0 });
//保存doc文件
document.SaveToFile("AppendBubbleChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Line chart.");
//创建一个新段落以附加折线图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Line, 500, 300);
//清除折线图的系列数据以从干净的图表开始
Chart chart = shape.Chart;
ChartTitle title = chart.Title;
title.Text = "My Chart";
ChartSeriesCollection seriesColl = chart.Series;
seriesColl.Clear();
//在图表内设置新数据
string[] categories = { "C1", "C2", "C3", "C4", "C5", "C6" };
seriesColl.Add("AW Series 1", categories, new double[] { 1, 2, 2.5, 4, 5, 6 });
seriesColl.Add("AW Series 2", categories, new double[] { 2, 3, 3.5, 6, 6.5, 7 });
//保存doc文件
document.SaveToFile("AppendLineChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Pie chart.");
//创建一个新段落以附加饼图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Pie, 500, 300);
Chart chart = shape.Chart;
//插入一个自定义图表系列,其中包含每个扇区的类别名称及其频率值。
ChartSeries series = chart.Series.Add("Test Series",
new[] { "Word", "PDF", "Excel" },
new[] { 2.7, 3.2, 0.8 });
//保存到docx文件。
document.SaveToFile("AppendPieChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Scatter chart.");
//创建一个新段落以附加散点图
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Scatter, 450, 300);
Chart chart = shape.Chart;
//清除图表的系列数据,以一个干净的图表开始
chart.Series.Clear();
//插入五个点的X/Y坐标系列
chart.Series.Add("Scatter chart",
new[] { 1.0, 2.0, 3.0, 4.0, 5.0 },
new[] { 1.0, 20.0, 40.0, 80.0, 160.0 });
//保存到docx文件
document.SaveToFile("AppendScatterChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Surface3D chart.");
//创建新段落以附加曲面三维图表
Paragraph newPara = section.AddParagraph();
ShapeObject shape = newPara.AppendChart(ChartType.Surface3D, 500, 300);
//清除其系列数据,以一个干净的图表开始
Chart chart = shape.Chart;
chart.Series.Clear();
chart.Title.Text = "My chart";
//添加三个系列
chart.Series.Add("Series 1",
new string[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
new double[] { 1900000, 850000, 2100000, 600000, 1500000 });
chart.Series.Add("Series 2",
new string[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
new double[] { 900000, 50000, 1100000, 400000, 2500000 });
chart.Series.Add("Series 3",
new string[] { "Word", "PDF", "Excel", "GoogleDocs", "Office" },
new double[] { 500000, 820000, 1500000, 400000, 100000 });
//保存到docx文件.
document.SaveToFile("AppendSurface3DChart.docx", FileFormat.Docx);//创建word文档
Document document = new Document();
//新建一个节
Section section = document.AddSection();
//创建新段落并附加文本
section.AddParagraph().AppendText("Bar chart.");
//创建一个新段落以附加条形图
Paragraph newPara = section.AddParagraph();
ShapeObject chartShape = newPara.AppendChart(ChartType.Bar, 400, 300);
Chart chart = chartShape.Chart;
//使用“标题”属性为条形图提供一个标题,该标题显示在图表区域的顶部中心。
ChartTitle title = chart.Title;
title.Text = "My Chart";
//将“Show”属性设置为“true”以使标题可见。
title.Show = true;
//将“Overlay”属性设置为“true”。允许其他图表元素与标题重叠,从而给它们更多的空间
title.Overlay = true;
//保存到docx文件
document.SaveToFile("AppendBarChart.docx", FileFormat.Docx);Document document = new Document();
Section section = document.AddSection();
string svgFile = "sample.svg";
Paragraph para = section.AddParagraph();
DocPicture svgPicture = para.AppendPicture(svgFile);
svgPicture.Width = 200;
svgPicture.Height = 200;
String DocxResult = "Result-AddSvg.docx";
document.SaveToFile(DocxResult, FileFormat.Docx2016);Document doc = new Document();
doc.LoadFromFile(https://cdn.e-iceblue.cn/inputFile, FileFormat.Docx);
System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
printDialog.PrinterSettings.PrintToFile = true;
printDialog.PrinterSettings.PrintFileName = "sample-new-4.xps";
doc.PrintDialog = printDialog;
doc.PrintMultipageToOneSheet(PagesPreSheet.FourPages, true);Document doc = new Document();
doc.LoadFromFile(https://cdn.e-iceblue.cn/inputFile, FileFormat.Docx);
FixedLayoutDocument layoutDoc = new FixedLayoutDocument(doc);
// 访问第一页的行并打印到控制台。
FixedLayoutLine line = layoutDoc.Pages[0].Columns[0].Lines[0];
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Line: " + line.Text);
//使用渲染的行,可以返回文档对象模型中的原始段落。
Paragraph para = line.Paragraph;
stringBuilder.AppendLine("Paragraph text: " + para.Text);
// 以纯文本格式(包括页眉和页脚)检索第一页上显示的所有文本。
string pageText = layoutDoc.Pages[0].Text;
stringBuilder.AppendLine(pageText);
// 循环遍历文档中的每一页,并打印每页上显示的行数。
foreach (FixedLayoutPage page in layoutDoc.Pages)
{
LayoutCollection lines = page.GetChildEntities(LayoutElementType.Line, true);
stringBuilder.AppendLine("Page " + page.PageIndex + " has " + lines.Count + " lines.");
}
// 此方法为任何给定节点提供布局实体的反向查找
// (页眉和页脚中的管路和节点除外)。
stringBuilder.AppendLine("The lines of the first paragraph:");
foreach (FixedLayoutLine paragraphLine in layoutDoc.GetLayoutEntitiesOfNode(
((Section)doc.FirstChild).Body.Paragraphs[0]))
{
stringBuilder.AppendLine(paragraphLine.Text.Trim());
stringBuilder.AppendLine(paragraphLine.Rectangle.ToString());
}
File.WriteAllText("page.txt", stringBuilder.ToString());