本文我们将介绍如何使用Spire.Presentation for java将Excel工作表作为OLE对象插入到幻灯片。
import com.spire.presentation.*;
import com.spire.presentation.drawing.IImageData;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
public class embedExcelAsOLE {
public static void main(String[] args) throws Exception{
//新建PowerPoint文档
Presentation ppt = new Presentation();
//插入图片到PowerPoint文档
File file =new File("Excel.png");
BufferedImage image = ImageIO.read(file);
IImageData oleImage = ppt.getImages().append(image);
Rectangle rec = new Rectangle(80, 60, image.getWidth(), image.getHeight());
//加载Excel文档
String input = "Sample.xlsx";
File oldFile=new File(input);
//将Excel数据保存到流
FileInputStream inputStream = new FileInputStream(oldFile);
byte[] data = new byte[(int)oldFile.length()];
inputStream.read(data,0,data.length);
//根据Excel数据将OLE对象插入到PowerPoint文档
com.spire.presentation.IOleObject oleObject=ppt.getSlides().get(0).getShapes().appendOleObject("excel", data, rec);
oleObject.getSubstituteImagePictureFillFormat().getPicture().setEmbedImage(oleImage);
oleObject.setProgId("Excel.Sheet.12");
//保存文档
ppt.saveToFile("output/embedExcelAsOLE.pptx", FileFormat.PPTX_2013);
inputStream.close();
}
}
效果图:

Spire.PDF for Android 3.1.0已发布。该版本增强了转换SVG到PDF的功能,修复了获取PDF文档水印失败的问题。详情请阅读以下内容。
问题修复:
https://www.e-iceblue.cn/Introduce/pdf-for-android-via-java.html
本文介绍如何使用Spire.PDF for .NET为PDF文档中的文字块加上行号。
原文档:

using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Texts;
using System.Drawing;
namespace AddLineNumber
{
class Program
{
static void Main(string[] args)
{
//创建PdfDocument对象
PdfDocument doc = new PdfDocument();
//加载PDF文档
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\input.pdf");
//获取第一页
PdfPageBase page = doc.Pages[0];
//查找第一行中的指定文字
PdfTextFinder finder = new PdfTextFinder(page);
finder.Options.Parameter = Spire.Pdf.Texts.TextFindParameter.WholeWord;
PdfTextFragment topLine = finder.Find(""成都冰蓝科技"")[0];
//获取行高
float lineHeight = topLine.Bounds[0].Height;
//获取一个y坐标,用于写入编号的起始y坐标
float y = topLine.Bounds[0].Location.Y - 2;
//获取第二行中的指定文字
PdfTextFinder secondfinder = new PdfTextFinder(page);
secondfinder.Options.Parameter = Spire.Pdf.Texts.TextFindParameter.WholeWord;
PdfTextFragment secondLine = secondfinder.Find(""Office控件产品"")[0];
//计算行间距
float lineSpacing = secondLine.Bounds[0].Top - topLine.Bounds[0].Bottom;
//查找最后一行中的指定文字
PdfTextFinder bottomfinder = new PdfTextFinder(page);
bottomfinder.Options.Parameter = Spire.Pdf.Texts.TextFindParameter.WholeWord;
PdfTextFragment bottomLine = bottomfinder.Find("开发并向他们")[0];
//获取获取最后一行的底部y坐标,亦即添加行号区域的高度
float height = bottomLine.Bounds[0].Bottom;
//创建一个字体,大小和PDF中文字大小一致
PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(new Font("黑体", 12f), true);
int i = 1;
while (y < height)
{
//绘制行号到每一行的前面
page.Canvas.DrawString(i.ToString(), trueTypeFont, PdfBrushes.Black, new PointF(15, y));
y += lineHeight + lineSpacing;
i++;
}
//保存文档
doc.SaveToFile("result.pdf");
}
}
}
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Texts
Imports System.Drawing
Namespace AddLineNumber
Class Program
Shared Sub Main(ByVal args() As String)
'创建PdfDocument对象
Dim doc As PdfDocument = New PdfDocument()
'加载PDF文档
doc.LoadFromFile("C:\Users\Administrator\Desktop\input.pdf")
'获取第一页
Dim page As PdfPageBase = doc.Pages(0)
'查找第一行中的指定文字
Dim finder As PdfTextFinder = New PdfTextFinder(page)
finder.Options.Parameter = TextFindParameter.WholeWord
Dim topLine As PdfTextFragment = finder.Find("成都冰蓝科技")(0)
'获取行高
Dim lineHeight As Single = topLine.Bounds(0).Height
'获取一个y坐标,用于写入编号的起始y坐标
Dim y As Single = topLine.Bounds(0).Location.Y - 2
'获取第二行中的指定文字
Dim secondfinder As PdfTextFinder = New PdfTextFinder(page)
secondfinder.Options.Parameter = TextFindParameter.WholeWord
Dim secondLine As PdfTextFragment = secondfinder.Find("Office控件产品")(0)
'计算行间距
Dim lineSpacing As Single = secondLine.Bounds(0).Top - topLine.Bounds(0).Bottom
'查找最后一行中的指定文字
Dim bottomfinder As PdfTextFinder = New PdfTextFinder(page)
bottomfinder.Options.Parameter = TextFindParameter.WholeWord
Dim bottomLine As PdfTextFragment = bottomfinder.Find("开发并向他们")(0)
'获取获取最后一行的底部y坐标,亦即添加行号区域的高度
Dim height As Single = bottomLine.Bounds(0).Bottom
'创建一个字体,大小和PDF中文字大小一致
Dim trueTypeFont As PdfTrueTypeFont = New PdfTrueTypeFont(New Font("黑体", 12.0F), True)
Dim i As Integer = 1
While y < height
'绘制行号到每一行的前面
page.Canvas.DrawString(i.ToString(), trueTypeFont, PdfBrushes.Black, New PointF(15, y))
y += lineHeight + lineSpacing
i += 1
End While
'保存文档
doc.SaveToFile("result.pdf")
End Sub
End Class
End Namespace
结果文档:

Spire.Doc 9.1已发布。该版本增强了转换Word到PDF的功能,修复了查找文本、加载和保存文档时出现的问题。详情请阅读以下内容。
问题修复:
Spire.Presentation for .NET 6.1版本支持嵌入Zip对象到PPT幻灯片。下面通过C#及VB.NET代码展示如何来实现Zip对象添加。在PPT中嵌入Excel对象可参考这篇文章。
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System;
using System.Drawing;
using System.IO;
namespace InsertZip
{
class Program
{
static void Main(string[] args)
{
//创建一个PPT文档,并获取第一张幻灯片(创建的PPT默认包含一张空白幻灯片)
Presentation ppt = new Presentation();
ISlide slide = ppt.Slides[0];
//读取zip文件到byte数组
byte[] data = File.ReadAllBytes("sample.zip");
//在幻灯片中绘制形状,并添加zip文件对象
Rectangle rec = new Rectangle(120, 120, 100, 100);
IOleObject ole = slide.Shapes.AppendOleObject("sample.zip", data, rec);
ole.ProgId = "Package";
//设置对象封面图片
Image image = Image.FromFile("logo.png");
IImageData oleImage = ppt.Images.Append(image);
ole.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage;
//保存文档
ppt.SaveToFile("InsertZip.pptx", Spire.Presentation.FileFormat.Pptx2013);
System.Diagnostics.Process.Start("InsertZip.pptx");
}
}
}
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing
Imports System.IO
Namespace InsertZip
Class Program
Private Shared Sub Main(args As String())
'创建一个PPT文档,并获取第一张幻灯片(创建的PPT默认包含一张空白幻灯片)
Dim ppt As New Presentation()
Dim slide As ISlide = ppt.Slides(0)
'读取zip文件到byte数组
Dim data As Byte() = File.ReadAllBytes("sample.zip")
'在幻灯片中绘制形状,并添加zip文件对象
Dim rec As New Rectangle(120, 120, 100, 100)
Dim ole As IOleObject = slide.Shapes.AppendOleObject("sample.zip", data, rec)
ole.ProgId = "Package"
'设置对象封面图片
Dim image__1 As Image = Image.FromFile("logo.png")
Dim oleImage As IImageData = ppt.Images.Append(image__1)
ole.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage
'保存文档
ppt.SaveToFile("InsertZip.pptx", Spire.Presentation.FileFormat.Pptx2013)
System.Diagnostics.Process.Start("InsertZip.pptx")
End Sub
End Class
End Namespace
嵌入效果:

Spire.PDF for Java 4.1.2现已发布。该版本主要修复了一些在PDF转HTML/图片和插入图片到PDF Grid单元格时出现的问题。详情如下。
问题修复:
Spire.PDF 7.1 已正式发布。该版本调整了pdftable.Style.DefaultStyle和pdftable.Style.AlternateStyle的属性注释,并修复了在压缩、打印、合并以及对PDF文档签名时出现的一些问题。详情如下。
改进:
问题修复:
Spire.Barcode for Java 4.1.2现已发布。该版本成功修复了扫描QR code二维码的数据不正确的问题以及在Linux系统下生成的Code128条形码数据显示不完全的问题。详情请查阅以下内容。
问题修复:
Spire.Email 4.1已发布。本次调整主要将ImapClient.MarkAsDeleted(int sequqnceNo)方法的参数类型由String改为int。详情请阅读以下内容。
调整变化:
Spire.Barcode 5.1已发布。该版本主要增强了扫描功能。详情请阅读以下内容。
问题修复: