Spire.Presentation 7.10.2 已发布。该版本支持读取图表数据是否启用了“切换行/列”功能。同时,该版本还修复了转换 PPT 到 PDF 后背景色不正确的问题。详情请阅读以下内容。
新功能:
bool result = chart.IsSwitchRowAndColumn();问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-NET.html
Spire.Office for Java 7.10.4 已发布。本次更新带来了一些新功能,如:Spire.Doc for Java 支持设置Word文档网格属性,并支持以流的方式判断docm格式的文件是否被加密。 同时,Spire.PDF for Java增强了 PDF 到图片的转换;Spire.XLS for Java增强了 Excel 到 PDF 的转换;Spire.Presentation for Java增强了 PPT 到 PDF、SVG 及图片的转换。此外,该版本还成功修复了许多已知问题。详情请阅读以下内容。
获取 Spire.Office for Java 7.10.4请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
新功能:
Document doc = new Document();
doc.loadFromFile("input.docx");
for (GridPitchType type : GridPitchType.values()) {
for (Object sec : doc.getSections()) {
((Section) sec).getPageSetup().setGridType(type);
((Section) sec).getPageSetup().setLinesPerPage(15);
}
doc.saveToFile("output.docx", FileFormat.Docx);
}
doc.close(); Document document = new Document();
FileInputStream inStream = new FileInputStream("data/WordWithMacro1.docm");
boolean isPwd = Document.isPassWordProtected(inStream);问题修复:
问题修复:
问题修复:
问题修复:
Spire.Doc for Java 10.10.7 已发布。本次更新新增支持设置Word文档网格属性及以流的方式判断 docm 格式的文件是否被加密。同时,该版本增强了 Word 到 PDF、Word 到 HTML、HTML 到 Word 和 Docm 到 Docx 的转换。此外,版本还修复了许多已知问题,如:邮件合并域更新不正确以及更新目录域程序抛异常“unpected cross ax”的问题。详情请阅读以下内容。
新功能:
Document doc = new Document();
doc.loadFromFile("input.docx");
for (GridPitchType type : GridPitchType.values()) {
for (Object sec : doc.getSections()) {
((Section) sec).getPageSetup().setGridType(type);
((Section) sec).getPageSetup().setLinesPerPage(15);
}
doc.saveToFile("output.docx", FileFormat.Docx);
}
doc.close(); Document document = new Document();
FileInputStream inStream = new FileInputStream("data/WordWithMacro1.docm");
boolean isPwd = Document.isPassWordProtected(inStream);问题修复:
页码对于电子文档和纸质文档都是必不可少的。 它们可以使读者更容易快速查找和访问文档的特定部分,而无需逐页浏览。 在本文中,您将学习如何使用 Spire.PDF for .NET 将页码添加到现有 PDF 文档中。
首先,您需要添加 Spire.PDF for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。
PM> Install-Package Spire.PDF您可以使用以下动态字段向 PDF 文档添加页码:PdfPageNumberField、PdfPageCountField 和 PdfCompositeField。
顾名思义,PdfPageNumberField 用于显示页码,PdfPageCountField 用于显示总页数,PdfCompositeField 用于将PdfPageNumberField 和 PdfPageCountField 等两个或多个动态字段组合成一个字段。
如果您只想将第 1 页、第 2 页、第 3 页等页码添加到 PDF 文档,您可以使用 PdfPageNumberField。 如果您想在文档中添加“第 X 页,共 Y 页”页码,您需要使用 PdfPageNumberField、PdfPageCountField 和 PdfCompositeField。
以下步骤向您展示如何将“第 X 页,共 Y 页”页码添加到现有 PDF 文档:
using Spire.Pdf;
using Spire.Pdf.AutomaticFields;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace AddPageNumbers
{
class Program
{
static void Main(string[] args)
{
//初始化 PdfDocument 类的实例
PdfDocument pdf = new PdfDocument();
//加载示例文档
pdf.LoadFromFile("示例文档.pdf");
//设置页码字体样式
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("宋体", 10f, FontStyle.Regular), true);
//初始化 PdfPageNumberField 类的实例
PdfPageNumberField pageNumber = new PdfPageNumberField();
//初始化PdfPageCountField 类的实例
PdfPageCountField pageCount = new PdfPageCountField();
//初始化PdfCompositeField 类的实例
PdfCompositeField compositeField = new PdfCompositeField(font, PdfBrushes.Black, "第{0}页,共{1}页", pageNumber, pageCount);
//设置复合字段的文本对齐方式
compositeField.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);
//循环遍历页面
for (int i = 0; i < pdf.Pages.Count; i++)
{
//在页面的特定位置绘制复合字段
compositeField.Draw(pdf.Pages[i].Canvas, pdf.Pages[i].Size.Width / 4 - 20, pdf.Pages[i].Size.Height / 2- 20);
}
//保存结果文档
pdf.SaveToFile("添加页码.pdf");
}
}
}Imports Spire.Pdf
Imports Spire.Pdf.AutomaticFields
Imports Spire.Pdf.Graphics
Namespace AddPageNumbers
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'初始化 PdfDocument 类的实例
Dim pdf As PdfDocument = New PdfDocument()
'加载示例文档
pdf.LoadFromFile("示例文档.pdf")
'设置页码字体样式
Dim font As PdfTrueTypeFont = New PdfTrueTypeFont(New Font("宋体", 10F, FontStyle.Regular), True)
'初始化 PdfPageNumberField 类的实例
Dim pageNumber As PdfPageNumberField = New PdfPageNumberField()
'初始化PdfPageCountField 类的实例
Dim pageCount As PdfPageCountField = New PdfPageCountField()
'初始化PdfCompositeField 类的实例
Dim compositeField As PdfCompositeField = New PdfCompositeField(font, PdfBrushes.Black, "第{0}页,共{1}页", pageNumber, pageCount)
'设置复合字段的文本对齐方式
compositeField.StringFormat = New PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top)
'循环遍历页面
For i As Integer = 0 To pdf.Pages.Count - 1
'在页面的特定位置绘制复合字段
compositeField.Draw(pdf.Pages(i).Canvas, pdf.Pages(i).Size.Width / 4 - 20, pdf.Pages(i).Size.Height / 2 - 20)
Next
'保存结果文档
pdf.SaveToFile("添加页码.pdf")
End Sub
End Class
End Namespace
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.XLS for Java 12.10.3已发布。本次更新增强了Excel 到 PDF的转换。一些已知问题也得到了修复,如修复了获取文件最后修改时间不正确等问题。详情请阅读以下内容。
问题修复:
如果要强调 Word 文档中的特定段落或文本,可以更改其字体颜色。 本文将演示如何使用 Spire.Doc for .NET 在 C# 和 VB.NET 中更改 Word 中的字体颜色。
首先,您需要添加 Spire.Doc for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。
PM> Install-Package Spire.Doc以下是更改 Word 文档中段落字体颜色的步骤:
using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
namespace ChangeFontColorForParagraph
{
class Program
{
static void Main(string[] args)
{
//创建一个Document实例
Document document = new Document();
//Load a Word document
document.LoadFromFile("示例.docx");
//获取第一节
Section section = document.Sections[0];
//更改第一段文本颜色
Paragraph p1 = section.Paragraphs[0];
ParagraphStyle s1 = new ParagraphStyle(document);
s1.Name = "Color1";
s1.CharacterFormat.TextColor = Color.RosyBrown;
document.Styles.Add(s1);
p1.ApplyStyle(s1.Name);
//更改第二段文本颜色
Paragraph p2 = section.Paragraphs[1];
ParagraphStyle s2 = new ParagraphStyle(document);
s2.Name = "Color2";
s2.CharacterFormat.TextColor = Color.MediumSlateBlue;
document.Styles.Add(s2);
p2.ApplyStyle(s2.Name);
//保存结果文档
document.SaveToFile("更改段落字体颜色.docx", FileFormat.Docx);
}
}
}Imports Spire.Doc
Imports Spire.Doc.Documents
Imports System.Drawing
Namespace ChangeFontColorForParagraph
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'创建一个Document实例
Dim document As Document = New Document()
'Load a Word document
document.LoadFromFile("示例.docx")
'获取第一节
Dim section As Section = document.Sections(0)
'更改第一段文本颜色
Dim p1 As Paragraph = section.Paragraphs(0)
Dim s1 As ParagraphStyle = New ParagraphStyle(document)
s1.Name = "Color1"
s1.CharacterFormat.TextColor = Color.RosyBrown
document.Styles.Add(s1)
p1.ApplyStyle(s1.Name)
'更改第二段文本颜色
Dim p2 As Paragraph = section.Paragraphs(1)
Dim s2 As ParagraphStyle = New ParagraphStyle(document)
s2.Name = "Color2"
s2.CharacterFormat.TextColor = Color.MediumSlateBlue
document.Styles.Add(s2)
p2.ApplyStyle(s2.Name)
'保存结果文档
document.SaveToFile("更改段落字体颜色.docx", FileFormat.Docx)
End Sub
End Class
End Namespace
以下是更改 Word 文档中特定文本字体颜色的步骤:
using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
namespace ChangeFontColorForText
{
class Program
{
static void Main(string[] args)
{
//创建一个Document实例
Document document = new Document();
//加载 Word 文档
document.LoadFromFile("示例.docx");
//查找指定文本
TextSelection[] text = document.FindAllString("Spire.Doc for .NET", false, true);
//更改特定文本的字体颜色
foreach (TextSelection seletion in text)
{
seletion.GetAsOneRange().CharacterFormat.TextColor = Color.Purple;
}
//保存结果文档
document.SaveToFile("更改特定文本字体颜色.docx", FileFormat.Docx);
}
}
}Imports Spire.Doc
Imports Spire.Doc.Documents
Imports System.Drawing
Namespace ChangeFontColorForText
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'创建一个Document实例
Dim document As Document = New Document()
'加载 Word 文档
document.LoadFromFile("示例.docx")
'查找需要更改字体颜色的文本
Dim text As TextSelection() = document.FindAllString("Spire.Doc for .NET", False, True)
'更改特定文本的字体颜色
For Each seletion As TextSelection In text
seletion.GetAsOneRange().CharacterFormat.TextColor = Color.Purple
Next
'保存结果文档
document.SaveToFile("更改特定文本字体颜色.docx", FileFormat.Docx)
End Sub
End Class
End Namespace
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Presentation for Java 7.10.1 已发布。本次更新增强了 PPT 到 PDF、SVG 以及图片的转换。同时,该版本还修复了一些已知问题,如加载 PPT 文件时,应用程序引发 “NullPointerException” 异常的问题。详情请阅读以下内容。
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-JAVA.html
Spire. XLS 12.10已发布。本次更新增强了Excel到PDF及XML到Excel 的转换。此外,此版本还修复了加载表单名包含字符“#”的Excel报错等已知问题。详情请阅读以下内容。
问题修复:
PowerPoint 中的超链接是可点击的对象,使你能够跳到同一/不同的 PowerPoint 文档中的另一张幻灯片或一个特定的网站。它们是为你的幻灯片添加额外资源的好方法,也可以使文档更具互动性。除了向 PowerPoint 文档添加超链接外,Spire.Presentation for Java 还支持修改和删除现有的超链接。本文将介绍如何实现上述两个功能。
首先,您需要在 Java 程序中添加 Spire.Presentation.jar 文件作为一个依赖项。您可以从这个链接下载 JAR 文件。如果您使用 Maven,则可以通过在 pom.xml 文件中添加以下代码轻松导入该 JAR 文件。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>11.9.10</version>
</dependency>
</dependencies>
使用 Spire.Presentation for Java,你可以为现有的超链接设置一个新的超链接地址和显示文本。以下是在 PowerPoint 中修改超链接的详细步骤。
import com.spire.presentation.*;
public class modifyHyperlink {
public static void main(String[] args) throws Exception {
//创建一个Presentation对象并加载一个PowerPoint文件
Presentation presentation = new Presentation();
presentation.loadFromFile("test.pptx");
//获取包含超链接的指定形状
IAutoShape shape = (IAutoShape)presentation.getSlides().get(0).getShapes().get(0);
//编辑超链接文本和地址
shape.getTextFrame().getTextRange().setText("Spire.Presentation for Java");
shape.getTextFrame().getTextRange().getClickAction().setAddress("https://www.e-iceblue.com/Introduce/presentation-for-java.html");
//保存文件
presentation.saveToFile("ModifyHyperlink.pptx", FileFormat.PPTX_2013);
}
}
当一个超链接由于某种原因需要被删除时,Spire.Persentation for Java 提供了 TextCharacterProperties.setClickAction() 方法。而通过设置其值为 null,你可以在 PowerPoint 中轻松删除超链接。详细步骤如下。
import com.spire.presentation.*;
public class removeHyperlink {
public static void main(String[] args) throws Exception {
//创建一个Presentation对象并加载一个PowerPoint文件
Presentation presentation = new Presentation();
presentation.loadFromFile("test.pptx");
//获取包含超链接的指定形状
IAutoShape shape = (IAutoShape)presentation.getSlides().get(0).getShapes().get(0);
//将点击动作设置为null来删除超链接
shape.getTextFrame().getTextRange().setClickAction(null);
//保存文件
presentation.saveToFile("RemoveHyperlink.pptx", FileFormat.PPTX_2013);
}
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
包含多个工作表的工作簿有助于集中管理相关信息,但有时我们必须将工作表拆分为单独的 Excel 文件,以便在不泄露其他信息的情况下分发单个工作表。 在本文中,您将学习如何使用 Spire.XLS for .NET 将 Excel 工作表拆分为单独的 Excel 文件。
首先,您需要将 Spire.XLS for .NET 包含的 DLL 文件作为引用添加到您的 .NET 项目中。DLL 文件可以从此链接下载,也可以通过 NuGet 安装。
PM> Install-Package Spire.XLS以下是使用 Spire.XLS for .NET 将 Excel 工作表拆分为单独 Excel 文件的主要步骤。
using Spire.Xls;
using System;
namespace SplitWorksheets
{
class Program
{
static void Main(string[] args)
{
//创建Workbook对象
Workbook wb = new Workbook();
//加载示例 Excel 文件
wb.LoadFromFile("数据.xlsx");
//声明一个新的 Workbook 变量
Workbook newWb;
//声明一个字符串变量
String sheetName;
//指定用于存储生成的 Excel 文件的文件夹路径
String folderPath = "C:\\Users\\Tina\\Desktop\\输出结果\\";
//循环遍历源文件中的工作表
for (int i = 0; i < wb.Worksheets.Count; i++)
{
//初始化Workbook对象
newWb = new Workbook();
//删除默认工作表
newWb.Worksheets.Clear();
//将源文档的特定工作表添加到新工作簿
newWb.Worksheets.AddCopy(wb.Worksheets[i]);
//获取worksheet名称
sheetName = wb.Worksheets[i].Name;
//将新工作簿保存到指定文件夹
newWb.SaveToFile(folderPath + sheetName + ".xlsx", ExcelVersion.Version2013);
}
}
}
}VB.NET
Imports Spire.Xls
Namespace SplitWorksheets
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'创建Workbook对象
Dim wb As Workbook = New Workbook()
'加载示例 Excel 文件
wb.LoadFromFile("数据.xlsx")
'声明一个新的 Workbook 变量
Dim newWb As Workbook
'声明一个字符串变量
Dim sheetName As String
'指定用于存储生成的 Excel 文件的文件夹路径
Dim folderPath = "C:\Users\Tina\Desktop\输出结果\"
'循环遍历源文件中的工作表
For i As Integer = 0 To wb.Worksheets.Count - 1
'初始化Workbook对象
newWb = New Workbook()
'删除默认工作表
newWb.Worksheets.Clear()
'将源文档的特定工作表添加到新工作簿
newWb.Worksheets.AddCopy(wb.Worksheets(i))
'获取worksheet名称
sheetName = wb.Worksheets(i).Name
'将新工作簿保存到指定文件夹
newWb.SaveToFile(folderPath & sheetName & ".xlsx", ExcelVersion.Version2013)
Next
End Sub
End Class
End Namespace
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。