我们很高兴地宣布 Spire.Doc 14.9.11 版本正式发布。本次更新新增 ImportOptions、ExportOptions 类,精细化管控文档加载与导出流程;支持 HTML 转 Word 时渲染 HSL 色彩;同时修复大量格式转换、文档编辑场景下的已知缺陷,详情如下。
调整:
- 内置类 Word 语言适配逻辑,默认跟随线程文化切换语言:ChinaPRC 文化环境加载中文,其余环境默认英文。该配置会改变生成文档的展示效果。
- 调整 .NET Core 打包方案,遵循 .NET Standard 规范实现跨平台兼容。仅更新 readme.txt 中 .NET 6.0 /.NET 9.0 /.NET 10.0 依赖项,其余平台无改动:
- 移除全部 AI 相关功能
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
新功能:
- 新增 ImportOptions、ExportOptions 配置类,用于自定义文档加载、导出行为,使用示例如下: 示例 1:密码加载加密文档
- 支持设置“相同样式段落间不添加间距”。
- 支持 HTML 内 HSL 色彩解析渲染。
- 支持移除图表边框。
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 转 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.Doc 14.9.11 请点击:







