冰蓝科技
|
028-81705109
|
|
微信扫一扫
|

Spire.Cloud 纯前端文档控件

本文介绍如何使用Spire.Presentation for Java更改PowerPoint中文本的字体样式,包括字体名称,字体大小,字体颜色,粗体,斜体等。

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;

public class ChangeFontStyles {

    public static void main(String[] args) throws Exception {

        //创建Presentation对象
        Presentation presentation = new Presentation();

        //加载示例文档
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");

        //获取文本形状
        IAutoShape shape = (IAutoShape) presentation.getSlides().get(0).getShapes().get(0);

        //获取第一个段落并更改字体颜色
        ParagraphEx paragraph = shape.getTextFrame().getParagraphs().get(0);
        for (int i = 0; i < paragraph.getTextRanges().getCount(); i++) {
            PortionEx textRange =  paragraph.getTextRanges().get(i);
            textRange.getFormat().getFill().setFillType(FillFormatType.SOLID);
            textRange.getFormat().getFill().getSolidColor().setColor(Color.blue);
        }

        //获取第三个段落并将文字加粗,设置斜体和下划线
        paragraph = shape.getTextFrame().getParagraphs().get(2);
        for (int i = 0; i < paragraph.getTextRanges().getCount(); i++) {
            PortionEx textRange = paragraph.getTextRanges().get(i);
            textRange.getFormat().isBold(TriState.TRUE);
            textRange.getFormat().isItalic(TriState.TRUE);
            textRange.getFormat().setTextUnderlineType(TextUnderlineType.DASHED);
        }

        //获取第五个段落并更改字体名称及大小
        paragraph = shape.getTextFrame().getParagraphs().get(4);
        for (int i = 0; i < paragraph.getTextRanges().getCount(); i++) {
            PortionEx textRange = paragraph.getTextRanges().get(i);
            textRange.getFormat().setEastAsianFont(new TextFont("黑体"));
            textRange.getFormat().setFontHeight(22f);
        }

        //保存文档
        presentation.saveToFile("output/ChangeFontStyles.pptx", FileFormat.PPTX_2013);
    }
}

Java 更改 PowerPoint 文档中的字体样式

Spire.PDFViewer 6.8.6已发布。本次更新带了些新功能,比如ASP.NET控件支持旋转页面,支持控件支持查找文本并高亮。同时,该版本还修复了PDF文档显示相关等问题。详情请阅读以下内容。

新功能:

问题修复:


获取Spire.PDFViewer 6.8.6请点击:

https://www.e-iceblue.cn/Downloads/Spire-PDFViewer-NET.html

本文将介绍如何使用Spire.Presentation for .NET在PowerPoint文档中使用正则表达式替换文本。

C#
using Spire.Presentation;
using System.Text.RegularExpressions;

namespace ReplaceTextWithRegex
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建Presentation实例
            Presentation ppt = new Presentation();
            //加载示例文档
            ppt.LoadFromFile("Sample.pptx");

            //获取第一张幻灯片
            ISlide slide = ppt.Slides[0];

            //替换该幻灯片中所有“ABC”以及其后到行尾的内容为“ABC def”
            Regex regex = new Regex("ABC.*");
            string newvalue = "ABC def";
            foreach (IShape shape in slide.Shapes)
            {
                shape.ReplaceTextWithRegex(regex, newvalue);
            }

            //保存结果文档
            ppt.SaveToFile("ReplaceTextWithRegex.pptx", FileFormat.Pptx2013);
        }
    }
}
VB.NET
Imports Spire.Presentation
Imports System.Text.RegularExpressions

Namespace ReplaceTextWithRegex
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            '创建Presentation实例
            Dim ppt As Presentation = New Presentation()
            '加载示例文档
            ppt.LoadFromFile("Sample.pptx")

            '获取第一张幻灯片
            Dim slide As ISlide = ppt.Slides(0)

            '替换该幻灯片中所有“ABC”以及其后到行尾的内容为“ABC def”
            Dim regex As Regex = New Regex("ABC.*")
            Dim newvalue As String = "ABC def"

            For Each shape As IShape In slide.Shapes
                shape.ReplaceTextWithRegex(regex, newvalue)
            Next

            '保存结果文档
            ppt.SaveToFile("ReplaceTextWithRegex.pptx", FileFormat.Pptx2013)
        End Sub
    End Class
End Namespace

原PowerPoint文档:

C#/VB.NET 在 PowerPoint 中使用正则表达式替换文本

结果文档:

C#/VB.NET 在 PowerPoint 中使用正则表达式替换文本

OFD 即 Open Fixed-layout Document,是我国国家版式文档格式标准。OFD 文档具有便携性、开放性、扩展性的特点。OFD 文件小,可压缩比率大,且呈现效果与设备无关。在各种设备上阅读、打印或印刷时可达到版面固定、不跑版的效果。在电子商务、电子公务、信息发布等领域都有广泛应用。在本文中,您将学习如何在 C# 和 VB.NET 中使用 Spire.PDF for .NET 将 PDF 转换为 OFD 文档。

安装 Spire.PDF for .NET

首先,您需要添加 Spire.PDF for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。

PM> Install-Package Spire.PDF

将 PDF 转换为 OFD

详细步骤如下:

  • C#
  • VB.NET
using Spire.Pdf;

namespace PDFtoOFD
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建PdfDocument 类的对象
            PdfDocument pdf = new PdfDocument();

            //加载PDF文档
            pdf.LoadFromFile("成都大运会竞技赛公告.pdf");

            //保存为OFD格式
            pdf.SaveToFile("ToOFD.ofd", FileFormat.OFD);
        }
    }
}
Imports Spire.Pdf

Namespace PDFtoOFD
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            '创建PdfDocument 类的对象
            Dim pdf As PdfDocument = New PdfDocument
            '加载PDF文档
            pdf.LoadFromFile("成都大运会竞技赛公告.pdf")
            '保存为OFD格式
            pdf.SaveToFile("ToOFD.ofd", FileFormat.OFD)
        End Sub
    End Class
End Namespace

C#/VB.NET 将 PDF 转为 OFD

申请临时 License

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。

Spire.Doc 9.8.6已发布。该版本增强了转换Word/RTF到PDF的功能,以及转换HTML到Word的功能。此外,本次更新还修复了加载Word文档时出现的问题。详情请阅读以下内容。

问题修复:


获取Spire.Doc 9.8.6请点击:

https://www.e-iceblue.cn/Downloads/Spire-Doc-NET.html

Spire.Office 6.8.2已发布。本次更新带来了许多出色的新功能,比如:Spire.Presentation支持加载保存 DPS/DPT 格式的文档,支持设置PPT中图表的边框样式为直角,同时还支持设置图表坐标轴的刻度线间隔;Spire.PDF 支持转换 PDF 到 OFD,支持给数字签名添加有效性检查标记,以及支持添加不可见的数字签名的功能;Spire.XLS 支持转换 SmartArt/Shape 为图片;Spire.Barcode 支持获取条码在图片中的位置和条码类型等等。此外,该版本还修复了大量已知的问题。详情请阅读以下内容。

该版本涵盖了最新版的Spire.Doc, Spire.PDF, Spire.XLS, Spire.Presentation, Spire.Email, Spire.DocViewer, Spire.PDFViewer, Spire.Spreadsheet, Spire.OfficeViewer, Spire.DataExport, Spire.Barcode。

版本信息如下:

获取Spire.Office 6.8.2请点击:

https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html


Spire.Doc

问题修复:


Spire.PDF

新功能:

问题修复:


Spire.Presentation

新功能:

问题修复:


Spire.XLS

新功能:

问题修复:


Spire.Barcode

新功能:

问题修复:


Spire.Email

问题修复:

Spire.PDF 7.8.8已发布。本次更新支持转换PDF到OFD,支持给数字签名添加有效性检查标记。此外,该版本还增强了转换PDF到SVG/图片/PDFA1B,以及XPS到PDF的功能。详情请阅读以下内容。

新功能:

问题修复:


获取Spire.PDF 7.8.8请点击:

https://www.e-iceblue.cn/Downloads/Spire-PDF-NET.html

Spire.Presentation 6.8.3已发布。该版本支持加载保存DPS/DPT格式的文档,支持设置PPT中图表的边框样式为直角,同时还支持在PPT中,使用正则表达式替换文本。此外,本次更新还增强了转换PPT到PDF的功能。详情请阅读以下内容。

新功能:

问题修复:


获取Spire.Presentation 6.8.3请点击:

https://www.e-iceblue.cn/Downloads/Spire-Presentation-NET.html

在这里您将以直观的形式体验冰蓝科技 Spire 系列文档处理组件的部分功能,例如:文档转换,您可以上传自己的文档,选择需要转换的结果文档格式,点击运行并查看转换结果。

如果您没有找到想要的 Demo,您可以通过填写表格获取免费定制 Demo 服务。定制 Demo 需满足以下条件:

Tab 1

此 Demo 展示如何使用 Marker Designer,基于模板导出 Excel。

Data

Name Capital Continent Area Population
ArgentinaBuenos AiresSouth America277781532300003
BoliviaLa PazSouth America10985757300000
BrazilBrasiliaSouth America8511196150400000
CanadaOttawaNorth America997614726500000
ChileSantiagoSouth America75694313200000
ColombiaBagotaSouth America113890733000000
CubaHavanaNorth America11452410600000
EcuadorQuitoSouth America45550210600000
El SalvadorSan SalvadorNorth America208655300000
GuyanaGeorgetownSouth America214969800000

Option

Excel Version:
downloads

如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo

如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。

Tab 2

using System.Data;
using Spire.Xls;
namespace DemoOnlineCode
{
    class MarkerDesigner
    {

        public void demoMarkerDesigner(string filePath,string dataFilePath,string resultFilePath)
        {
            Workbook data_book = new Workbook();
            data_book.LoadFromFile(dataFilePath);
            DataTable table = data_book.Worksheets[0].ExportDataTable();

            Workbook workbook = new Workbook();
            workbook.LoadFromFile(filePath);
            Worksheet sheet = workbook.Worksheets[0];
            Worksheet sheet2 = workbook.Worksheets[1];

            sheet.Name = "Result";
            sheet2.Name = "DataSource";
            sheet2.InsertDataTable(table, true, 1, 1);

            workbook.MarkerDesigner.AddParameter("Variable1", 1234.5678);
            workbook.MarkerDesigner.AddDataTable("Country", table);
            workbook.MarkerDesigner.Apply();

            sheet.AllocatedRange.AutoFitRows();
            sheet.AllocatedRange.AutoFitColumns();
            workbook.SaveToFile(resultFilePath, ExcelVersion.Version2010);



        }
    }
}

Tab 3

Imports System.Data
Imports Spire.XLS
Namespace DemoOnlineCode
    Class MarkerDesigner

        Public Sub demoMarkerDesigner(filePath As String, dataFilePath As String, resultFilePath As String)
            Dim data_book As New Workbook()
            data_book.LoadFromFile(dataFilePath)
            Dim table As DataTable = data_book.Worksheets(0).ExportDataTable()

            Dim workbook As New Workbook()
            workbook.LoadFromFile(filePath)
            Dim sheet As Worksheet = workbook.Worksheets(0)
            Dim sheet2 As Worksheet = workbook.Worksheets(1)

            sheet.Name = "Result"
            sheet2.Name = "DataSource"
            sheet2.InsertDataTable(table, True, 1, 1)

            workbook.MarkerDesigner.AddParameter("Variable1", 1234.5678)
            workbook.MarkerDesigner.AddDataTable("Country", table)
            workbook.MarkerDesigner.Apply()

            sheet.AllocatedRange.AutoFitRows()
            sheet.AllocatedRange.AutoFitColumns()
            workbook.SaveToFile(resultFilePath, ExcelVersion.Version2010)



        End Sub
    End Class
End Namespace