Spire.Office 11.9.0 已正式发布。该版本新增了一些功能,如Spire.Doc 新增文档加载与导出控制类;Spire.XLS 新增支持 TRANSPOSE 公式。除此之外,一些在操作Word、Excel、PDF和PPT文档时出现的问题也已成功被修复。更多新功能及问题修复详情如下。
该版本涵盖了最新版的Spire.Doc、Spire.PDF、Spire.XLS、Spire.Presentation、Spire.DataExport、Spire.Barcode、Spire.DocViewer、Spire.PDFViewer、Spire.OfficeViewer、Spire.Email。
版本信息如下:
- Spire.Doc.dll: 14.9.11
- Spire.XLS.dll: 16.9.2
- Spire.Presentation.dll: 11.9.1
- Spire.Pdf.dll: 12.9.18
- Spire.Barcode.dll: 7.5.13
- Spire.DocViewer.dll v8.9.5
- Spire.Email.dll v6.8.0
- Spire.OfficeViewer.dll v8.8.1
- Spire.PdfViewer.Asp.dll v8.3.0
- Spire.PdfViewer.Forms.dll v8.3.0
- Spire.Spreadsheet.dll v7.5.3
获取Spire.Office 11.9.0,请点击:
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
Spire.Doc
调整:
- 调整 .NET Core 打包方案,遵循 .NET Standard 规范实现跨平台兼容。仅更新 readme.txt 中 .NET 6.0 /.NET 9.0 /.NET 10.0 依赖项,其余平台无改动:
net6.0 外部依赖:
SkiaSharp >= 3.116.1
Microsoft.Win32.Registry >= 5.0.0
System.Buffers >= 4.5.1
System.Memory >= 4.5.5
System.Text.Encoding.CodePages >= 6.0.0
HarfBuzzSharp >=8.3.0.1
net9.0 外部依赖:
SkiaSharp >= 3.116.1
Microsoft.Win32.Registry >= 5.0.0
System.Buffers >= 4.5.1
System.Memory >= 4.5.5
System.Text.Encoding.CodePages >= 9.0.0
HarfBuzzSharp >=8.3.0.1
net10.0 外部依赖:
SkiaSharp >= 3.116.1
Microsoft.Win32.Registry >= 5.0.0
System.Buffers >= 4.5.1
System.Memory >= 4.5.5
System.Text.Encoding.CodePages >= 10.0.0
HarfBuzzSharp >=8.3.0.1
Image img = document.SaveToImages(0, ImageType.Bitmap);
img.Save("sample.png", ImageFormat.Png);
SkiaSharp.SKImage images = document.SaveToImages(0, ImageType.Bitmap);
FileStream fileStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
images.Encode(SkiaSharp.SKEncodedImageFormat.Png, 100).SaveTo(fileStream);
fileStream.Flush();
新功能:
- 支持创建自定义文档主题
- 支持将现有文档的主题复制至其他文档
- 支持获取、修改文档主题。
- 支持配置「仅嵌入文档所用字符」字体子集嵌入
- 支持设置图表及图表数据系列的填充样式。
- 新增 ImportOptions、ExportOptions 配置类,用于自定义文档加载、导出行为,使用示例如下: 示例 1:密码加载加密文档
- 支持设置“相同样式段落间不添加间距”。
- 支持 HTML 内 HSL 色彩解析渲染。
- 支持移除图表边框。
// Create a new document and apply the theme
Document doc = new Document();
// Configure a custom theme
Theme theme = doc.Theme;
theme.MajorFonts.Latin = "Courier New"; // Set the heading font to Courier New
theme.MinorFonts.Latin = "Agency FB"; // Set the body font to Agency FB
ThemeColors colors = theme.Colors;
colors.Dark1 = Color.MidnightBlue;
colors.Light1 = Color.PaleGreen;
colors.Dark2 = Color.Indigo;
colors.Light2 = Color.Khaki;
colors.Accent1 = Color.OrangeRed;
colors.Accent2 = Color.LightSalmon;
colors.Accent3 = Color.Yellow;
colors.Accent4 = Color.Gold;
colors.Accent5 = Color.BlueViolet;
colors.Accent6 = Color.DarkViolet;
colors.Hyperlink = Color.Black;
colors.FollowedHyperlink = Color.Gray;
Section section = doc.AddSection();
// Create a heading and apply MajorFonts and the Accent1 color
Paragraph heading = section.AddParagraph();
heading.AppendText("Document Theme Test");
heading.ApplyStyle(BuiltinStyle.Heading1);
// Link the heading style to MajorFonts
ParagraphStyle heading1Style = (ParagraphStyle)doc.Styles["Heading 1"];
heading1Style.CharacterFormat.ThemeFont = ThemeFont.Major; // Use the Major theme font (heading font)
heading1Style.CharacterFormat.ThemeColor = ThemeColor.Accent1; // Use the Accent1 theme color
// Create a body paragraph and apply MinorFonts
Paragraph body = section.AddParagraph();
body.AppendText("This document uses a custom theme created programmatically.");
// Link the Normal style to MinorFonts
ParagraphStyle normalStyle = (ParagraphStyle)doc.Styles["Normal"];
normalStyle.CharacterFormat.ThemeFont = ThemeFont.Minor; // Use the Minor theme font (body font)
normalStyle.CharacterFormat.ThemeColor = ThemeColor.Text1; // Use the default text color
// Add a test paragraph to verify the theme color
Paragraph colorTest = section.AddParagraph();
TextRange textRange = colorTest.AppendText("Accent1 Color Test");
textRange.CharacterFormat.ThemeColor = ThemeColor.Accent1; // Use the Accent1 theme color directly
doc.SaveToFile(outputFile, FileFormat.Docx);
doc.Close();
// Load the source document and get its theme
Document sourceDoc = new Document();
sourceDoc.LoadFromFile("Theme.docx");
Theme sourceTheme = sourceDoc.Theme;
// Create a destination document
Document newDoc = new Document();
// Copy the source document's theme (theme fonts and colors) to the destination document
sourceDoc.CloneThemesTo(newDoc);
newDoc.SaveToFile("CopyTheme.docx", FileFormat.Docx);
Document doc = new Document();
// Set the font faces of the document theme
doc.Theme.MinorFonts.Latin = "Algerian";
doc.Theme.MinorFonts.EastAsian = "Aharoni";
doc.Theme.MinorFonts.ComplexScript = "Andalus";
// Set the theme font and theme color of the style's character format
CharacterFormat font = ((ParagraphStyle)doc.Styles["Normal"]).CharacterFormat;
font.ThemeFont = ThemeFont.Minor;
font.ThemeColor = ThemeColor.Accent2;
// Get the theme font and theme color
ThemeFont themeFont = font.ThemeFont;
string fontName = font.FontName;
Color textColor = font.TextColor;
doc.SaveToFile("ThemeAttributes.docx", FileFormat.Docx);
doc.setEmbedFontsInFile(true);
doc.setSaveSubsetFonts(true);
// Create a document and add a column chart
Document doc = new Document();
Section section = doc.AddSection();
ShapeObject shape = section.AddParagraph().AppendChart(ChartType.Column, 500, 300);
Chart chart = shape.Chart;
chart.Series.Clear();
chart.Series.Add("Sales", new string[] { "Q1", "Q2", "Q3", "Q4" }, new double[] { 120, 90, 160, 200 });
// Chart area - solid fill
chart.Format.Fill.FillType = FillType.Solid;
chart.Format.Fill.Color = Color.OrangeRed;
chart.Format.Fill.Transparency = 0.3;
// Data points of the first series - linear gradient fill
Fill seriesFill = chart.Series[0].DataPoints.Format.Fill;
seriesFill.FillType = FillType.Shade;
seriesFill.GradientType = GradientFillType.Linear;
seriesFill.SetGradientDirection(GradientFillDirection.LinearUp);
seriesFill.GradientStops.Add(new GradientStop(0, Color.White));
seriesFill.GradientStops.Add(new GradientStop(1, Color.OrangeRed));
// Data labels - enable and use a solid fill
chart.Series[0].HasDataLabels = true;
chart.Series[0].DataLabels.Format.Fill.FillType = FillType.Solid;
chart.Series[0].DataLabels.Format.Fill.Color = Color.LightYellow;
doc.SaveToFile("ChartFill.docx", FileFormat.Docx);
// Create a document and add a line chart
Document doc = new Document();
Section section = doc.AddSection();
ShapeObject shape = section.AddParagraph().AppendChart(ChartType.Line, 500, 300);
Chart chart = shape.Chart;
chart.Series.Clear();
chart.Series.Add("Trend", new string[] { "Cat1", "Cat2", "Cat3", "Cat4" }, new double[] { 4.3, 2.4, 3.1, 5.2 });
// Chart area - border weight, dash style and solid color
chart.Format.Stroke.Weight = 2;
chart.Format.Stroke.DashStyle = DashStyle.Dash;
chart.Format.Stroke.Fill.FillType = FillType.Solid;
chart.Format.Stroke.Fill.Color = Color.Blue;
// Data series border - set through its data points
chart.Series[0].DataPoints.Format.Stroke.Fill.FillType = FillType.Solid;
chart.Series[0].DataPoints.Format.Stroke.Fill.Color = Color.Red;
chart.Series[0].DataPoints.Format.Stroke.Weight = 1.5;
// Start and end arrows on the axes
chart.AxisX.Format.Stroke.StartArrowType = ArrowType.Arrow;
chart.AxisX.Format.Stroke.EndArrowType = ArrowType.Arrow;
chart.AxisY.Format.Stroke.StartArrowType = ArrowType.Arrow;
chart.AxisY.Format.Stroke.EndArrowType = ArrowType.Arrow;
doc.SaveToFile("ChartStroke.docx", FileFormat.Docx);
using Spire.Doc;
using Spire.Doc.Importing;
var importOptions = new ImportOptions { Password = "123456" };
var doc = new Document();
doc.LoadFromFile("encrypted.docx", importOptions);
using Spire.Doc;
using Spire.Doc.Importing;
// 实现资源加载回调类
public class MyAssetLoader : IAssetLoadingCallback
{
public AssetLoadingAction AssetLoading(AssetLoadingArgs args)
{
// 拦截追踪类图片
if (args.Url.Contains("tracker"))
return AssetLoadingAction.Block;
// 带鉴权加载自定义图片资源
if (args.AssetType == AssetType.Image && args.Url.StartsWith("https://api."))
{
var data = LoadWithAuth(args.Url);
args.SetData(data);
return AssetLoadingAction.Custom;
}
// 重定向CDN地址至本地镜像
if (args.Url.Contains("cdn.example.com"))
{
args.Url = args.Url.Replace("cdn.example.com", "local.mirror.com");
return AssetLoadingAction.Download;
}
// 默认逻辑:从原地址下载资源
return AssetLoadingAction.Download;
}
}
// 传入回调加载文档
var doc = new Document();
var options = new ImportOptions
{
AssetLoadingCallback = new MyAssetLoader()
};
doc.LoadFromFile("document.html", options);
using Spire.Doc;
using Spire.Doc.Exporting;
var doc = new Document();
doc.LoadFromFile("input.docx");
// 使用默认DOC格式导出
//var options = new DocExportOptions();
// 使用默认DOCX格式导出
var options = new DocxExportOptions();
doc.SaveToFile("output.docx", options);
// 指定Word 2019版本格式导出
doc.SaveToFile("output.docx", new DocxExportOptions(FileFormat.Docx2019));
using Spire.Doc;
using Spire.Doc.Exporting;
// 1. 实现进度回调接口
public class ProgressReporter : IExportingProgressCallback
{
public void OnProgress(ExportingProgressArgs args)
{
// 进度取值范围0~100
Console.WriteLine($"导出进度: {args.EstimatedProgressPercentage:F1}%");
// 如需终止导出,可在此抛出异常
}
}
// 2. 绑定回调并执行导出
var doc = new Document();
doc.LoadFromFile("large-document.docx");
var options = new DocxExportOptions(FileFormat.Docx)
{
ProgressCallback = new ProgressReporter()
};
doc.SaveToFile("output.docx", options);
Document doc = ConvertUtil.GetNewEngineDocument();
Section section = doc.AddSection();
ParagraphStyle heading1 = (ParagraphStyle)doc.Styles["Heading 1"];
Assert.IsFalse(heading1.ParagraphFormat.NoSpaceBetweenSameStyle);
heading1.ParagraphFormat.NoSpaceBetweenSameStyle = true;
Spire.Doc.Documents.Paragraph sameStyle1 = AddParagraph(section, SameStyleText1, BuiltinStyle.Heading1);
Spire.Doc.Documents.Paragraph sameStyle2 = AddParagraph(section, SameStyleText2, BuiltinStyle.Heading1);
Spire.Doc.Documents.Paragraph otherStyle = AddParagraph(section, OtherStyleText, BuiltinStyle.Heading2);
doc.SaveToFile(outputFile_temp, FileFormat.Docx);
Document doc = new Document();
Section sec = doc.AddSection();
Paragraph para = sec.AddParagraph();
para.AppendHTML("<p style=\"color:hsl(0,75%,60%)\">Hello</p>");
doc.SaveToFile("HtmlTest_hsl.docx");
Document doc = new Document();
doc.LoadFromFile(@"input.docx");
foreach (Paragraph para in doc.Sections[0].Paragraphs)
{
foreach (DocumentObject obj in para.ChildObjects)
{
if (obj is ShapeObject shape && shape.Chart != null)
{
Chart chart = shape.Chart;
// 清除图表绘图区边框
chart.Format.Stroke.Fill.FillType = FillType.NoFill;
}
}
}
doc.SaveToFile("NoBorder.docx", FileFormat.Docx);
问题修复:
- 修复删除 Word 页面时多删页面的问题。
- 修复 Word 转 PDF 时部分 Symbol 字体字符丢失的问题。
- 修复 Word 转 PDF 内容格式错乱问题。
- 修复 Word 转 PDF 表格解析异常问题。
- 修复含合并单元格文档转 PDF 后表格样式错乱问题。
- 修复 Word 转 PDF 内容排版变动问题。
- 修复 LaTeX 公式解析错误问题。
- 修复 Word 转 PDF 页面布局偏移问题。
- 修复插入 SVG 至 Word 时触发索引越界异常。
- 修复 Word 转 HTML 再转回 Word 下划线丢失问题。
- 修复加载 WPS 加密文档报错问题。
- 修复 Word 转 PDF 交叉引用上标样式改变问题。
- 修复复制 Word 内容后艺术字效果丢失问题。
- 修复添加超链接后直接导出 PDF 超链接丢失问题。
- 修复表格插入分页符后导出 PDF 触发空引用异常。
- 修复内容替换为空字符串后转 PDF 文字丢失问题。
- 修复公式内 {aligned} 标识无法识别、换行失效问题。
- 修复 Word 转 PDF 彩色表情变为黑白问题。
- 修复 Word 公式转 MathML 后文字自动斜体问题。
- 修复 Word 转 PDF 触发参数异常问题。
- 修复 InsertPageNumbers 方法设置页码位置失效问题。
- 修复文档保存后 WPS 内页码显示红色问题。
- 修复 Word 转 PDF/A-1b 部分字符无法映射问题。
- 修复更新目录域代码失败问题。
- 修复使用 FixedLayoutDocument 加载文档触发空对象报错。
Spire.XLS
新功能:
- 新增支持TRANSPOSE公式。
sheet.Range["F1:H4"].FormulaArray = "=TRANSPOSE(A2:D4)";
问题修复:
- 修复了 Excel 转 PDF 时,列宽不一致的问题。
- 修复了 Excel 转 PDF时,边框变粗的问题。
- 修复了 ExportDataTable 导出数据不正确的问题。
Spire.Presentation
新功能:
- 新增 Paragraphs.AppendOfficeMathML() 方法,用于添加 Office 公式。
Presentation ppt = new Presentation();
IAutoShape autoShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(100, 100, 300, 200));
string txtContent = File.ReadAllText(inputFile);
autoShape.TextFrame.Paragraphs.AppendOfficeMathML(txtContent);
ppt.SaveToFile(outputFile, FileFormat.Pptx2013);
ppt.Dispose();
问题修复:
- 修复了 PPT 转 PDF 时文字模糊不清的问题。
Spire.PDF
新功能:
- 新增支持以流式布局模式添加内容来创建 PDF。(注:目前只支持创建,不支持对已有文档的加载修改)
- 将创建注释集合的方式从 PdfPageBase.AnnotationsV2 调整为 PdfAnnotationCollection.Create(page)。
// 创建 pdf 文档
PdfDocument pdf = new PdfDocument();
// 创建 PdfContentBuilder
PdfContentBuilder builder = new PdfContentBuilder(pdf);
// 添加第一节
var s1 = builder.AddSection();
s1.AddHeading1("Section One");
s1.AddParagraph("First flowing paragraph.");
// 添加第二节
var s2 = builder.AddSection();
s2.AddHeading1("Section Two");
s2.AddParagraph("Second flowing paragraph.");
// 添加第三节(只含段落)
var s3 = builder.AddSection();
s3.AddParagraph("Third section, only a paragraph.");
// 添加第四节,包含标题和导航条目
var s4 = builder.AddSection();
var h1 = s4.AddHeading(1, "Alpha Chapter");
var h2 = s4.AddHeading(2, "Beta Section");
var h3 = s4.AddHeading(3, "Gamma Subsection");
h1.AsNavigationEntry("Alpha Chapter", 1);
h2.AsNavigationEntry("Beta Section", 2);
h3.AsNavigationEntry("Gamma Subsection", 3);
s4.AddParagraph("Body copy under the headings.");
// 构建文档
var result = builder.Build();
// 保存文档
String outputFile = "Bug_1_MultipleSections.pdf";
pdf.SaveToFile(outputFile);
pdf.Close();
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();
RectangleF rect = new RectangleF(140, 689, 80, 1);
PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(page, rect, new PointF(140, 690), new PointF(220, 690));
lineAnnotation.Contents = "This is the first line annotation";
//新方式
PdfAnnotationCollection anmotationCollection = PdfAnnotationCollection.Create(page);
anmotationCollection.Add(lineAnnotation);
//原方式
//page.AnnotationsV2.Add(lineAnnotation);
问题修复:
- 修复了 XPS 转 PDF 时缩放图片丢失的问题。(SPIREPDF-8101)
- 修复了使用 InsertPage 复制页面时,表单字段丢失的问题。
- 修复了生成的标签结构 PDF 文档无法完全通过 PDF/UA (ISO 14289-1) 验证的问题。
- 修复了加载 FDF 时,抛出“NullReferenceException”的问题。
- 修复了获取图片的坐标和尺寸不正确的问题。
- 修复了创建表单域时,出现域名重复的问题。
调整:
- 优化了 PDF 转 SVG 的转换耗时问题。(SPIREPDF-8133)
Spire.Barcode
问题修复:
- 修复了条码数据读取不正确的问题







