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

Spire.Cloud 纯前端文档控件

IXLSRange接口下提供了getStyle() 方法和setStyle() 方法,用来获取或设置特定单元格(区域)的样式。要将格式从一个单元格复制到另一个单元格,请先获取样式,然后将其应用到另一个单元格。

import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class CopyCellFormatting {
    public static void main(String[] args) {

        //创建Workbook对象
        Workbook workbook = new Workbook();

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

        //获取第一个工作表
        Worksheet sheet = workbook.getWorksheets().get(0);

        //获取被使用的行数
        int rowCount = sheet.getRows().length;

        //遍历行
        for (int i = 1; i < rowCount + 1; i++)
        {
            //获取指定单元格的样式并应用到另一个单元格
            sheet.getRange().get(String.format("C%d",i)).setStyle(sheet.getRange().get(String.format("A%d",i)).getStyle());
        }

        //保存文档
        workbook.saveToFile("output/CopyFormatting.xlsx", ExcelVersion.Version2016);
    }
}

Java 复制 Excel 单元格的格式

经常有客户反馈,在Windows系统中,使用Spire组件转换文档时,结果文档正常,但是在Linux系统中,结果文档会出现乱码、方框或程序抛出字体缺失异常如:Cannot found font[SansSerif] installed on the system。

这个问题是由于Linux服务器缺少字体所导致。Spire组件转换文档时需要从系统中寻找对应的字体绘制字形,如果系统中没有安装原文档中所使用的字体,会先从系统已安装的字体中匹配能支持这个字形的字体,如果无法匹配出相应的字体,结果文档就会出现乱码或方框,或者程序会抛出字体缺失异常。若您遇到了这类问题,请先确认原文档中使用了哪些字体,然后将这些字体或Windows中的所有字体安装到您的Linux系统后,问题会得到解决。

以下是如何查看和安装字体的详细指令。

1、开启 root 权限

输入指令: su root 不行时,需要先输入指令: sudo passwd root

根据步骤输入密码,然后再重新输入指令: su root

2、将字体文件先放到某一个文件夹下

然后进入文件夹输入指令: cp simsun.ttc /usr/share/fonts/ ,依次输入下面的指令:

mkfontscale //字体扩展

mkfontdir //新增字体目录

fc-cache-fv //刷新缓存

3、查看安装的字体文件

查看系统中的字体:

指令:fc-list

查看系统中的中文字体:

指令:fc-list:lang=zh


如果按照上述步骤安装字体后,问题依然存在,请及时联系我们:该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。 或致电 028-81705109。

本文介绍如何使用Spire.XLS for Java来压缩Excel中的图片。

import com.spire.xls.*;

public class CompressImgs {
    public static void main(String[] args) {
        Workbook wb = new Workbook();
        wb.loadFromFile("test.xlsx");//加载Excel测试文档

        //遍历工作表
        for(int s = 0; s < wb.getWorksheets().getCount(); s++)
        {
            Worksheet sheet = wb.getWorksheets().get(s);

            //遍历工作表中的图片
            for(int p = 0; p < sheet.getPictures().getCount(); p++)
            {
                ExcelPicture pic = sheet.getPictures().get(p);
                pic.compress(40);//压缩图片
            }

        }

        //保存文档
        wb.saveToFile("CompressImgs.xlsx",FileFormat.Version2013);
        wb.dispose();
    }
}

压缩前后,可查看文档大小效果对比:

Java 压缩 Excel 中的图片

本文介绍如何使用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