本文将介绍如何使用Spire.XLS for Java将Excel工作表中的单列文本拆分为多列。
原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);
}
}
结果文档:

Spire.XLS for Java 3.5.7 现已发布。该版本支持拷贝单元格时只保留公式值,并新增了转换Excel到HTML的方法。除此之外,一些在转换Excel到图片及复制sheet时出现的问题也得以成功解决。详情见下文。
新功能:
Worksheet sheet = workbook.getWorksheets().get(0);
CopyRangeOptions copyOptions = CopyRangeOptions.OnlyCopyFormulaValue;
sheet.copy(sheet.getCellRange("A6:E6"), sheet.getCellRange("A8:E8"), EnumSet.of(copyOptions));
workbook.saveToFile(filename,FileFormat.HTML)
问题修复:
本文将详细介绍如何使用Spire.Presentation for Java给PPT文档添加图片水印。
示例文档:

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);
}
}
效果图:

Spire.PDF 6.5.15已发布。该版本主要修复了一些在提取文本、转换PDF为HTML、打印PDF文档和填充表单域时出现的一些问题。问题修复详情如下。
问题修复:
Spire.Spreadsheet 4.5.0已正式发布。该版本支持获取设置了数字格式的单元格的文本,同时也成功修复了设置sheet的格式不生效的问题。详情请参阅以下内容。
新功能:
string text = spreadsheet1.ActiveWorksheet[0,0].Text;
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Spreadsheet-NET.html
Spire.Doc 8.5.8现已发布。此次更新主要修复了一些在转换RTF到Doc以及加载文档时出现的问题。具体修复内容如下。
问题修复:
Spire.Barcode 4.5.1已正式发布。具体更新内容如下。
新功能:
通过添加标注可对特定内容进行解释、说明或其他附加内容等,本文介绍使用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();
}
}
标注添加结果如下,鼠标移动至相应标注内容上可弹出标注提示内容:

今天我们正式发布了Spire.Office for Java 3.5.0,该版本带来了一些不错的新功能,例如,Spire.PDF支持数字签名时添加时间戳,支持各种形状的注释框到PDF;Spire.Presetation 支持获取形状中文本输入区域的最大宽度。具体更新内容如下。
问题修复:
新功能:
IAutoShape shape = (IAutoShape) ppt.getSlides().get(0).getShapes().get(0);
float maxWidth = shape.getTextFrame().getMaxWidth();
IAutoShape shape = (IAutoShape) ppt.getSlides().get(0).getShapes().get(0);
double x = shape.getTextFrame().getStartLocationAtMaxWidth().getX();
double y = shape.getTextFrame().getStartLocationAtMaxWidth().getY();
问题修复:
新功能:
//配置时间戳服务器
String url = "https://freetsa.org/tsr";
signature.configureTimestamp(url);
signature.addShowConfigureText(SignatureConfigureText.Contact_Info);//显示Contact_Info(默认显示所有)
signature.removeShowConfigureText(SignatureConfigureText.Contact_Info);//不显示Contact_Info
signature.setShowConfigureText(EnumSet.of(SignatureConfigureText.Contact_Info));//只显示Contact_Info
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 leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
page.getCanvas().drawString(text1, font, brush1, 50, 50, leftAlignment);
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() - 60),
(int) (92 + bounds.getWidth()), (int) (page.getSize().getHeight() - bounds.getY() - 60)};
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(Color.GRAY));
((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(Color.RED));
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(30, (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(Color.RED));
annotation4.setModifiedDate(new Date());
annotation4.setName("*****");
LineBorder border2 = new LineBorder();
border2.setBorderWidth(2);
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(300, 450),
new Point2D.Float(300, 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(Color.GRAY));
((PdfNewPage) page).getAnnotations().add(annotation5);
pdf.saveToFile("output/annotation.pdf");
for (PdfPageBase page : (Iterable) doc.getPages()) {
content.append(page.extractText(true,true,true));
}
问题修复:
Spire.Presentation for Java 3.5.4已发布。该版本新增了支持在形状中获取文本输入区域的最大宽度,以及获取形状中文本输入区域的宽度最大时文本的起始坐标等功能。此外,也成功修复了在将PPTX文档转换成图片、获取表格单元格中文本颜色、加载文件以及设置数据表格边框时出现的一些问题。新功能及问题修复详情见下文。
新功能:
IAutoShape shape = (IAutoShape) ppt.getSlides().get(0).getShapes().get(0);
float maxWidth = shape.getTextFrame().getMaxWidth();
IAutoShape shape = (IAutoShape) ppt.getSlides().get(0).getShapes().get(0);
double x = shape.getTextFrame().getStartLocationAtMaxWidth().getX();
double y = shape.getTextFrame().getStartLocationAtMaxWidth().getY();
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-JAVA.html