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

Spire.Cloud 纯前端文档控件

本文将介绍如何使用Spire.XLS for Java将Excel工作表中的单列文本拆分为多列。

原Excel文档:

Java 实现 Excel 文本分列

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

public class ConvertTextToColumns {
    public static void main(String[] args){
        //创建Workbook实例
        Workbook workbook = new Workbook();
        //加载Excel文档
        workbook.loadFromFile("Template.xlsx");

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

        String[] splitText = null;
        String text = null;
        //将工作表中第一列的文本根据分隔符(空格)拆分为多列
        for (int i = 1; i < sheet.getLastRow()+1; i++)
        {
            text = sheet.getRange().get(i, 1).getText();
            splitText = text.split(" ");
            for (int j = 0; j < splitText.length; j++)
            {
                sheet.getRange().get(i, 1 + j + 1).setText(splitText[j]);
            }
        }

        //保存结果文档
        workbook.saveToFile("ConvertTextToColumns.xlsx", ExcelVersion.Version2013);
    }
}

结果文档:

Java 实现 Excel 文本分列

Spire.XLS for Java 3.5.7 现已发布。该版本支持拷贝单元格时只保留公式值,并新增了转换Excel到HTML的方法。除此之外,一些在转换Excel到图片及复制sheet时出现的问题也得以成功解决。详情见下文。

新功能:

问题修复:


获取Spire.XLS for Java 3.5.7,请点击:

https://www.e-iceblue.cn/Downloads/Spire-XLS-JAVA.html

本文将详细介绍如何使用Spire.Presentation for Java给PPT文档添加图片水印。

示例文档:

Java 给 PowerPoint 文档添加图片水印

import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.io.File;


public class addImageWatermark {

    public static void main(String[] args) throws Exception {
        //加载示例文档
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //获取水印图片
        File file =new File("logo.png");
        IImageData image = presentation.getImages().append(ImageIO.read(file));

        //获取幻灯片背景属性,设置图片填充      
        presentation.getSlides().get(0).getSlideBackground().setType(BackgroundType.CUSTOM);
        presentation.getSlides().get(0).getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
        presentation.getSlides().get(0).getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
        presentation.getSlides().get(0).getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(image);

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

效果图:

Java 给 PowerPoint 文档添加图片水印

Spire.PDF 6.5.15已发布。该版本主要修复了一些在提取文本、转换PDF为HTML、打印PDF文档和填充表单域时出现的一些问题。问题修复详情如下。

问题修复:


获取Spire.PDF 6.5.15,请点击:

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

Spire.Spreadsheet 4.5.0已正式发布。该版本支持获取设置了数字格式的单元格的文本,同时也成功修复了设置sheet的格式不生效的问题。详情请参阅以下内容。

新功能:

问题修复:


获取Spire.Spreadsheet 4.5.0,请点击:

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

Spire.Doc 8.5.8现已发布。此次更新主要修复了一些在转换RTF到Doc以及加载文档时出现的问题。具体修复内容如下。

问题修复:


获取Spire.Doc 8.5.8,请点击:

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

Spire.Barcode 4.5.1已正式发布。具体更新内容如下。

新功能:


获取Spire.Barcode 4.5.1,请点击:

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

通过添加标注可对特定内容进行解释、说明或其他附加内容等,本文介绍使用Spire.PDF for Java在PDF文档中添加多种不同类型的标注的方法,包括箭头、云朵、椭圆、矩形和连接线条等形状类型。

import com.spire.pdf.*;
import com.spire.pdf.annotations.*;
import com.spire.pdf.graphics.*;

import java.awt.*;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Date;

public class AddAnnotations {
    public static void main(String[] args) throws Exception{
        //创建PDF文档,添加一页
        PdfDocument pdf = new PdfDocument();
        PdfPageBase page = pdf.getPages().add();

        //添加箭头标注
        String text1 = "this is Arrow annotation";//指定文本字符串内容
        PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 20);//创建字体
        PdfSolidBrush brush1 = new PdfSolidBrush(new PdfRGBColor(Color.blue));//创建画刷
        PdfStringFormat Alignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);//设置文本对齐方式
        page.getCanvas().drawString(text1, font, brush1, 50, 70, Alignment);//绘制文本到页面

        Dimension2D dimension = font.measureString(text1);
        Rectangle2D.Float bounds = new Rectangle2D.Float(50, 50, (float) dimension.getWidth(), (float) dimension.getHeight());
        int[] linePoints = new int[]{92, (int) (page.getSize().getHeight() - bounds.getY() - 90),
                (int) (92 + bounds.getWidth()), (int) (page.getSize().getHeight() - bounds.getY() - 90)};
        PdfLineAnnotation annotation1 = new PdfLineAnnotation(linePoints, "LineArrow annotation test");
        annotation1.setBeginLineStyle(PdfLineEndingStyle.OpenArrow); 
        annotation1.setEndLineStyle(PdfLineEndingStyle.OpenArrow);
        annotation1.setBackColor(new PdfRGBColor(Color.red));
        annotation1.setCaptionType(PdfLineCaptionType.Inline);
        annotation1.setLineCaption(true);
        ((PdfNewPage) page).getAnnotations().add(annotation1);//添加标注

        //添加云朵标注
        String text2 = "this is Cloud annotation";
        PdfBrush brush2 = PdfBrushes.getBlue();
        page.getCanvas().drawString(text2, font, brush2, 50, 200);

        Point2D point2D[] = new Point2D[]{
                new Point2D.Float(30, 200),
                new Point2D.Float(300, 180),
                new Point2D.Float(300, 250),
                new Point2D.Float(30, 220),
                new Point2D.Float(30, 200)
        };
        PdfPolygonAnnotation annotation2 = new PdfPolygonAnnotation(page, point2D);
        annotation2.setText("PolygonCloud annotation test");
        annotation2.setAuthor("E-iceblue");
        annotation2.setSubject("test");
        annotation2.setModifiedDate(new Date());
        annotation2.setBorderEffect(PdfBorderEffect.Big_Cloud);//设置边框为云朵状的标注
        annotation2.setLocation(new Point2D.Float(190, 230));
        annotation2.setColor(new PdfRGBColor(new Color(34,139,34)));
        ((PdfNewPage) page).getAnnotations().add(annotation2);//添加标注


        //添加椭圆标注
        String text3 = "this is Circle annotation";
        PdfBrush brush3 = PdfBrushes.getBlue();
        Dimension2D dimension2D = font.measureString(text3);
        dimension2D.setSize(dimension2D.getWidth() + 35, dimension2D.getHeight() + 20);
        page.getCanvas().drawString(text3, font, brush3, 50, 300);

        Rectangle2D.Float annotationBounds1 = new Rectangle2D.Float();
        annotationBounds1.setFrame(new Point2D.Float(36, (float) 290), dimension2D);
        PdfSquareAndCircleAnnotation annotation3 = new PdfSquareAndCircleAnnotation(annotationBounds1);
        annotation3.setSubType(PdfSquareAndCircleAnnotationType.Circle);//设置椭圆标注
        float[] f1 = {0.5f, 0.5f, 0.5f, 0.5f};
        annotation3.setRectangularDifferenceArray(f1);
        annotation3.setText("Circle annotation test");
        annotation3.setColor(new PdfRGBColor(new Color(255,0,0)));
        annotation3.setModifiedDate(new Date());
        annotation3.setName("*****");
        LineBorder border1 = new LineBorder();
        border1.setBorderWidth(2);
        annotation3.setLineBorder(border1);
        ((PdfNewPage) page).getAnnotations().add(annotation3);//添加标注

        //添加矩形标注
        String text4 = "this is Square annotation";
        PdfBrush brush4 = PdfBrushes.getBlue();
        Dimension2D dimension4 = font.measureString(text4);
        dimension2D.setSize(dimension2D.getWidth() + 80, dimension2D.getHeight() + 20);
        page.getCanvas().drawString(text4, font, brush4, 50, 400);

        Rectangle2D.Float annotationBounds2 = new Rectangle2D.Float();
        annotationBounds2.setFrame(new Point2D.Float(50, (float) 400), dimension4);//矩形位置
        PdfSquareAndCircleAnnotation annotation4 = new PdfSquareAndCircleAnnotation(annotationBounds2);
        annotation4.setSubType(PdfSquareAndCircleAnnotationType.Square);//设置矩形标注
        float[] f2 = {0.5f, 0.5f, 0.5f, 0.5f};
        annotation4.setRectangularDifferenceArray(f2);
        annotation4.setText("Square annotation test");
        annotation4.setColor(new PdfRGBColor(new Color(255,0,255)));
        annotation4.setModifiedDate(new Date());
        LineBorder border2 = new LineBorder();
        border2.setBorderWidth(1);
        annotation4.setLineBorder(border2);
        ((PdfNewPage) page).getAnnotations().add(annotation4);

        //添加连接线标注
        String text5 = "this is Connected lines annotation";
        PdfBrush brush5 = PdfBrushes.getBlue();
        page.getCanvas().drawString(text5, font, brush5, 50, 465);
        Point2D pointzd[] = new Point2D[]{
                new Point2D.Float(30, 470),
                new Point2D.Float(350, 450),
                new Point2D.Float(350, 520),
                new Point2D.Float(30, 490),
                new Point2D.Float(30, 470)
        };
        PdfPolygonAnnotation annotation5 = new PdfPolygonAnnotation(page, pointzd);
        annotation5.setText("Connected Lines annotation test");
        annotation5.setAuthor("冰蓝");
        annotation5.setSubject("test");
        annotation5.setModifiedDate(new Date());
        annotation5.setBorderEffect(PdfBorderEffect.None);
        annotation5.setLocation(new Point2D.Float(190, 230));
        annotation5.setColor(new PdfRGBColor(new Color(255,215,0)));
        ((PdfNewPage) page).getAnnotations().add(annotation5);

        //保存文档
        pdf.saveToFile("AddAnnotations.pdf");
        pdf.dispose();
    }
}

标注添加结果如下,鼠标移动至相应标注内容上可弹出标注提示内容:

Java 在 PDF 中添加标注(Annotation)

今天我们正式发布了Spire.Office for Java 3.5.0,该版本带来了一些不错的新功能,例如,Spire.PDF支持数字签名时添加时间戳,支持各种形状的注释框到PDF;Spire.Presetation 支持获取形状中文本输入区域的最大宽度。具体更新内容如下。

Spire.Doc for Java

问题修复:

Spire.Presentation for Java

新功能:

问题修复:

Spire.PDF for Java

新功能:

问题修复:


获取Spire.Office for Java 3.5.0,请点击:

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

Spire.Presentation for Java 3.5.4已发布。该版本新增了支持在形状中获取文本输入区域的最大宽度,以及获取形状中文本输入区域的宽度最大时文本的起始坐标等功能。此外,也成功修复了在将PPTX文档转换成图片、获取表格单元格中文本颜色、加载文件以及设置数据表格边框时出现的一些问题。新功能及问题修复详情见下文。

新功能:

问题修复:


获取Spire.Presentation for Java 3.5.4,请点击:

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