我们很高兴地宣布,Spire.Office 11.3.0 正式发布。在此版本中,新增支持将 Word 转换为 Excel,以及添加和操作 SmartArt 图形;Spire.XLS 新增对 VBA 宏项目的操作支持;Spire.PDFViewer 现已支持基于 .NET 6.0 的 WPF 和 WinForms 应用程序。此外,本版本还修复了大量已知问题。
本次发布集成了以下组件的最新版本:Spire.Doc、Spire.PDF、Spire.XLS、Spire.Presentation、Spire.Barcode、Spire.DocViewer、Spire.PDFViewer、Spire.Email、Spire.Spreadsheet 和 Spire.OfficeViewer。
版本信息如下:
- Spire.Doc.dll v14.3.5
- Spire.PDF.dll v12.3.7
- Spire.XLS.dll v16.3.6
- Spire.Presentation.dll v11.3.1
- Spire.Barcode.dll v7.5.0
- Spire.Email.dll v6.8.0
- Spire.DocViewer.Forms.dll v8.9.5
- Spire.PdfViewer.Asp.dll v8.2.13
- Spire.PdfViewer.Forms.dll v8.2.13
- Spire.Spreadsheet.dll v7.5.3
- Spire.OfficeViewer.Forms.dll v8.8.1
获取Spire.Office 11.3.0,请点击:
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
Spire.Doc
新功能:
- 支持设置“定义网格时自动调整为右缩进”功能。
- 支持设置“为字体调整字间距”功能。
- 支持添加和操作 SmartArt 图形。
- 支持获取 SmartArt 中所有节点的文本。
- 增加对 Word 转 Excel 的支持。
paragraph.Format.AdjustRightIndent =true;//默认值是true
textRange.CharacterFormat.Kerning = 2.5f;
Document document = new Document();
Section section = document.AddSection();
Spire.Doc.Documents.Paragraph paragraph = section.AddParagraph(); paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center;
Spire.Doc.Fields.TextRange textRange = paragraph.AppendText("RepeatingBendingProcess");
textRange.CharacterFormat.FontSize = 28f;
textRange.CharacterFormat.FontName = "Times New Roman";
paragraph = section.AddParagraph();
paragraph = section.AddParagraph();
paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center;
// 添加采用“分段流程”版式的SmartArt图形
Spire.Doc.Fields.Shapes.Shape shape = paragraph.AppendSmartArt(SmartArtType.RepeatingBendingProcess, 432, 252);
SmartArt repeatingBendingSmartArt = shape.SmartArt;
// 添加节点文本
SmartArtNode process1 = repeatingBendingSmartArt.Nodes[0];
process1.Text = "1";
((Spire.Doc.Fields.TextRange)process1.Paragraphs[0].ChildObjects[0]).CharacterFormat.FontName = "Calibri";
((Spire.Doc.Fields.TextRange)process1.Paragraphs[0].ChildObjects[0]).CharacterFormat.FontSize = 20f;
((Spire.Doc.Fields.TextRange)process1.Paragraphs[0].ChildObjects[0]).CharacterFormat.TextColor = Color.Crimson;
// 添加节点文本
SmartArtNode process2 = repeatingBendingSmartArt.Nodes[1];
process2.Text = "2";
((Spire.Doc.Fields.TextRange)process2.Paragraphs[0].ChildObjects[0]).CharacterFormat.FontSize = 15f;
// 添加节点文本
SmartArtNode process3 = repeatingBendingSmartArt.Nodes[2];
process3.Text = "3";
((Spire.Doc.Fields.TextRange)process3.Paragraphs[0].ChildObjects[0]).CharacterFormat.FontSize = 10f;
// 添加节点文本
SmartArtNode process4 = repeatingBendingSmartArt.Nodes[3];
process4.Text = "4";
((Spire.Doc.Fields.TextRange)process4.Paragraphs[0].ChildObjects[0]).CharacterFormat.FontSize = 10f;
// 添加节点文本
SmartArtNode process5 = repeatingBendingSmartArt.Nodes[4];
process5.Text = "5";
((Spire.Doc.Fields.TextRange)process5.Paragraphs[0].ChildObjects[0]).CharacterFormat.FontSize = 10f;
document.SaveToFile(outputFile, FileFormat.Docx);
document.Close();
using (Document document = new Document(inputFile))
{
// 遍历所有节
foreach (Section section in document.Sections)
{
if (section?.Paragraphs == null) continue;
// 遍历节内所有段落
foreach (Spire.Doc.Documents.Paragraph paragraph in section.Paragraphs)
{
foreach (var childObj in paragraph.ChildObjects)
{
if (childObj is Spire.Doc.Fields.Shapes.Shape shape && shape.HasSmartArt)
{
SmartArt smartArt = shape.SmartArt;
if (smartArt == null) continue;
TraverseSmartArtNodes(smartArt.Nodes, builder, 0);
}
}
}
}
}
public static void TraverseSmartArtNodes(SmartArtNodeCollection nodes, StringBuilder builder, int level)
{
if (nodes == null || nodes.Count == 0) return;
for (int nodeIdx = 0; nodeIdx < nodes.Count; nodeIdx++)
{
SmartArtNode node = nodes[nodeIdx];
if (node == null) continue;
// 清理节点文本
string nodeText = node.Text != null ? node.Text.Trim() : "空文本";
if (nodeText == "\r" || string.IsNullOrEmpty(nodeText)) continue;
// 拼接节点层级标识
string nodePrefix;
switch (level)
{
case 0:
nodePrefix = "smartArt.Nodes";
break;
case 1:
nodePrefix = "smartArt.Nodes.ChildNodes";
break;
case 2:
nodePrefix = "smartArt.Nodes.ChildNodes.ChildNodes";
break;
default:
nodePrefix = $"smartArt.Nodes.Level{level}";
break;
}
// 基础文本输出
builder.AppendLine($"{nodePrefix}_{nodeIdx}:{nodeText}");
// 递归处理子节点
TraverseSmartArtNodes(node.ChildNodes, builder, level + 1);
}
}
Document.SaveToFile("output.xlsx", FileFormat.XLSX);
调整:
- 将 HtmlExportOptions 从 Spire.Doc 移动到 Spire.Doc.Exporting。
- 将 MarkdownExportOptions 从 Spire.Doc 移动到 Spire.Doc.Exporting。
问题修复:
- 修复了获取段落文本不正确的问题。
- 修复了转换 Word 到 PDF,阿拉伯文本字体被改变的问题。
- 修复了提取页面出现多余空白页的问题
Spire.XLS
新功能:
- 支持添加 VBA 宏工程。
Workbook workbook = new Workbook();
// 添加VBA工程到文档
IVbaProject vbaProject = workbook.VbaProject;
vbaProject.Name = "SampleVBAMacro";
string text = "修改前编码:" + vbaProject.CodePage.ToString() + "\n";
vbaProject.CodePage = 936; //设置编码,支持中文
text += "修改后编码:" + vbaProject.CodePage.ToString() + "\n";
File.WriteAllText(outputFile_TXT, text);
// 将 VBA 模块添加到项目中
IVbaModule vbaModule = vbaProject.Modules.Add("SampleModule", VbaModuleType.Module);
// 设置 VBA 宏源代码
vbaModule.SourceCode = @"
Sub ExampleMacro()
' 声明变量
Dim ws As Worksheet
Dim i As Integer
' 设置引用到活动工作表
Set ws = ActiveSheet
' 清除工作表内容(可选)
ws.Cells.Clear
' 填充示例数据
With ws
' 写入标题行
.Range(""A1:C1"").Value = Array(""序号"", ""项目名称"", ""金额"")
' 循环填充10行数据
For i = 1 To 10
.Cells(i + 1, 1).Value = i ' 序号列
.Cells(i + 1, 2).Value = ""Project "" & i ' 项目名称列
.Cells(i + 1, 3).Value = i * 100 ' 金额列(示例计算)
Next i
' 自动调整列宽
.Columns(""A:C"").AutoFit
' 格式化标题行
With .Range(""A1:C1"")
.Font.Bold = True
.Interior.Color = RGB(200, 220, 255) ' 浅蓝色背景
End With
' 格式化金额列
.Range(""C2:C11"").NumberFormat = ""$#,##0.00""
End With
' 显示完成消息
MsgBox ""数据填充完成!"", vbInformation, ""操作提示""
End Sub";
// Save the Excel file
workbook.SaveToFile(outputFile_Xls, FileFormat.Version97to2003);
- 支持读取VBA 宏工程。
Workbook wb = new Workbook();
wb.LoadFromFile(inputFile);
Worksheet ws = wb.Worksheets[0];
IVbaProject vbaProject = wb.VbaProject;
string text = "是否加密保护:" + vbaProject.IsProtected + "\n";
text += "名称:" + vbaProject.Name + "\n";
text += "描述:" + vbaProject.Description + "\n";
text += "帮助文件名称:" + vbaProject.HelpFileName + "\n";
text += "条件编译参数:" + vbaProject.ConditionalCompilation + "\n";
text += "是否锁定工程查看:" + vbaProject.LockProjectView + "\n";
text += "密码:" + vbaProject.Password + "\n";
text += "代码页:" + vbaProject.CodePage + "\n";
IVbaModule mod = vbaProject.Modules.GetWorksheetModule(ws);
text += "VBA 模块接口:" + "\n";
text += "模块名称:" + mod.Name.ToString() + "\n";
text += "源代码:\n" + mod.SourceCode.ToString() + "\n";
text += "模块类型:" + mod.Type.ToString() + "\n";
File.WriteAllText(outputFile_TXT, text.ToString());
vbaProject.Modules.Clear();
wb.SaveToFile(outputFile);
- 支持编辑 VBA 宏工程。
Workbook wb = new Workbook();
wb.LoadFromFile(inputFile);
Worksheet ws = wb.Worksheets[0];
IVbaProject vbaProject = wb.VbaProject;
vbaProject.Password = "1234";
vbaProject.Name = "modify";
vbaProject.Description = "Description";
vbaProject.HelpFileName = "image1.png";
vbaProject.ConditionalCompilation = "DEBUG = 2";
vbaProject.LockProjectView = true;
IVbaModule mod = vbaProject.Modules.GetWorksheetModule(ws);
mod.Name = "IVbaModule";
mod.SourceCode = "Dim lRow As Long";
mod.Type = VbaModuleType.Module;
wb.SaveToFile(outputFile);
- 支持删除 VBA 宏工程。
Workbook wb1 = new Workbook();
wb1.LoadFromFile(inputFile_1);
IVbaProject vbaProject1 = wb1.VbaProject;
vbaProject1.Modules.Remove("SampleModule");
vbaProject1.Modules.RemoveAt(0);
wb1.SaveToFile(outputFile_1);
- 支持创建多个情景方案。
Workbook wb = new Workbook();
wb.LoadFromFile(inputFile);
Worksheet worksheet = wb.Worksheets[0];
// 访问工作表中的情景集合
XlsScenarioCollection scenarios = worksheet.Scenarios;
// 为情景初始化存储不同数值的列表对象
List<object> currentChangePercentage_Values = new List<object> { 0.23, 0.8, 1.1, 0.5, 0.35, 0.2 };
List<object> increasedChangePercentage_Values = new List<object> { 0.45, 0.56, 0.9, 0.5, 0.58, 0.43 };
List<object> decreasedChangePercentage_Values = new List<object> { 0.3, 0.2, 0.5, 0.3, 0.5, 0.23 };
List<object> currentQuantity_Values = new List<object> { 1500, 3000, 5000, 4000, 500, 4000 };
List<object> increasedQuantity_Values = new List<object> { 1000, 5000, 4500, 3900, 10000, 8900 };
List<object> decreasedQuantity_Values = new List<object> { 1000, 2000, 3000, 3000, 300, 4000 };
// 在工作表中,为同一组单元格添加携带不同数值的情景
scenarios.Add("Current % of Change", worksheet.Range["F5:F10"], currentChangePercentage_Values);
scenarios.Add("Increased % of Change", worksheet.Range["F5:F10"], increasedChangePercentage_Values);
scenarios.Add("Decreased % of Change", worksheet.Range["F5:F10"], decreasedChangePercentage_Values);
scenarios.Add("Current Quantity", worksheet.Range["D5:D10"], currentQuantity_Values);
scenarios.Add("Increased Quantity", worksheet.Range["D5:D10"], increasedQuantity_Values);
scenarios.Add("Decreased Quantity", worksheet.Range["D5:D10"], decreasedQuantity_Values);
// 保存工作簿
wb.SaveToFile(outputFile, ExcelVersion.Version2013);
wb.Dispose();
- 支持生成情景摘要报告
Workbook wb = new Workbook();
wb.LoadFromFile(inputFile);
Worksheet worksheet = wb.Worksheets[0];
// 访问工作表中的情景集合
XlsScenarioCollection scenarios = worksheet.Scenarios;
// 为情景初始化存储不同数值的列表对象
List<object> currentChangePercentage_Values = new List<object>{ 0.23, 0.8, 1.1, 0.5, 0.35, 0.2 };
List<object> increasedChangePercentage_Values = new List<object> { 0.45, 0.56, 0.9, 0.5, 0.58, 0.43 };
List<object> decreasedChangePercentage_Values = new List<object> { 0.3, 0.2, 0.5, 0.3, 0.5, 0.23 };
List<object> currentQuantity_Values = new List<object> { 1500, 3000, 5000, 4000, 500, 4000 };
List<object> increasedQuantity_Values = new List<object> { 1000, 5000, 4500, 3900, 10000, 8900 };
List<object> decreasedQuantity_Values = new List<object> { 1000, 2000, 3000, 3000, 300, 4000 };
// 在工作表中,为同一组单元格添加携带不同数值的情景
scenarios.Add("Current % of Change", worksheet.Range["F5:F10"], currentChangePercentage_Values);
scenarios.Add("Increased % of Change", worksheet.Range["F5:F10"], increasedChangePercentage_Values);
scenarios.Add("Decreased % of Change", worksheet.Range["F5:F10"], decreasedChangePercentage_Values);
scenarios.Add("Current Quantity", worksheet.Range["D5:D10"], currentQuantity_Values);
scenarios.Add("Increased Quantity", worksheet.Range["D5:D10"], increasedQuantity_Values);
scenarios.Add("Decreased Quantity", worksheet.Range["D5:D10"], decreasedQuantity_Values);
// 创建摘要汇总
worksheet.Scenarios.Summary(worksheet.Range["L7"]);
// 保存工作簿
wb.SaveToFile(outputFile, ExcelVersion.Version2013);
wb.Dispose();
- 支持编辑情景方案
Workbook wb = new Workbook();
wb.LoadFromFile(inputFile);
Worksheet worksheet = wb.Worksheets[0];
// 访问工作表中的情景集合
XlsScenarioCollection scenarios = worksheet.Scenarios;
XlsScenario scenario1 = scenarios[0];
XlsScenario scenario2 = scenarios[1];
// 修改情景方案
scenario1.SetVariableCells(worksheet.Range["A1:A5"], scenario2.Values);
CellRange sourceCell = worksheet.Range["B1:B5"];
scenario2.SetVariableCells(sourceCell, scenario2.Values);
scenario1.Show();
scenario2.Show();
// 保存工作簿
wb.SaveToFile(outputFile, ExcelVersion.Version2013);
wb.Dispose();
- 支持合并情景方案
Workbook wb = new Workbook();
wb.LoadFromFile(inputFile);
Worksheet worksheet1 = wb.Worksheets[0];
Worksheet worksheet2 = wb.Worksheets[1];
// 合并情景方案
worksheet1.Scenarios.Merge(worksheet2);
// 保存工作簿
wb.SaveToFile(outputFile, ExcelVersion.Version2013);
wb.Dispose();
- 支持删除情景方案
Workbook wb = new Workbook();
wb.LoadFromFile(inputFile);
Worksheet worksheet = wb.Worksheets[0];
// 访问工作表中的情景集合
XlsScenarioCollection scenarios = worksheet.Scenarios;
// 删除情景方案
scenarios.RemoveScenarioAt(0);
scenarios.RemoveScenarioByName("two");
string content = "";
content += "Count:" + scenarios.Count + "\n";
content += "ContainsScenario:" + scenarios.ContainsScenario("two").ToString() + "\n";
content += "ContainsScenario:" + scenarios.ContainsScenario("one").ToString() + "\n";
File.WriteAllText(outputFile, content.ToString());
// 保存工作簿
wb.SaveToFile(outputFile, ExcelVersion.Version2013);
wb.Dispose();
问题修复:
- 修复了复制工作表,宏丢失的问题。
Spire.Presentation
问题修复:
- 修复了无法获取形状阴影效果的问题。
- 修复了转换 PowerPoint 文档到 PDF 文档时,文本偏移的问题。
- 修复了加载包含 3D 动画的 PowerPoint 文档时,程序抛出 “Property not found” 异常的问题。
- 修复了转换 PowerPoint 文档到 PDF 文档时,程序抛出 “Object reference not set to an instance of an object.” 异常的问题。
Spire.PDF
问题修复:
- 修复了合并PDF程序抛出“System.OutOfMemoryException”异常的问题。
- 修复了合并PDF文档后,输出文档无法在浏览器打开的问题。
- 修复了转换PDF到ToPdfA1A等标准格式后,复选项的打勾符号丢失的问题。
- 修复了转换PDF到Word,内容格式不正确的问题。
- 修复了转换PDF到图片程序抛出“System.NullReferenceException”异常的问题。
- 修复了加载PDF程序抛出“An item with the same key has already been added”异常的问题。
- 修复了设置查找区域后,查找文本不正确的问题。
Spire.PDFViewer
新功能:
- 新增支持 .NET 6.0 WPF 和 WinForms 平台。







