Java (480)
This article demonstrates how to extract OLE objects from an Excel document using Spire.XLS for Java.
import com.spire.xls.*;
import com.spire.xls.core.IOleObject;
import java.io.*;
public class ExtractOLEObjects {
public static void main(String[] args){
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load the Excel document
workbook.loadFromFile("OLEObjectsExample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
//Extract ole objects
if (sheet.hasOleObjects()) {
for (int i = 0; i < sheet.getOleObjects().size(); i++) {
IOleObject object = sheet.getOleObjects().get(i);
OleObjectType type = sheet.getOleObjects().get(i).getObjectType();
switch (type) {
//Word document
case WordDocument:
byteArrayToFile(object.getOleData(), "output/extractOLE.docx");
break;
//PowerPoint document
case PowerPointSlide:
byteArrayToFile(object.getOleData(), "output/extractOLE.pptx");
break;
//PDF document
case AdobeAcrobatDocument:
byteArrayToFile(object.getOleData(), "output/extractOLE.pdf");
break;
//Excel document
case ExcelWorksheet:
byteArrayToFile(object.getOleData(), "output/extractOLE.xlsx");
break;
}
}
}
}
public static void byteArrayToFile(byte[] datas, String destPath) {
File dest = new File(destPath);
try (InputStream is = new ByteArrayInputStream(datas);
OutputStream os = new BufferedOutputStream(new FileOutputStream(dest, false));) {
byte[] flush = new byte[1024];
int len = -1;
while ((len = is.read(flush)) != -1) {
os.write(flush, 0, len);
}
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
The following screenshot shows the extracted OLE documents:

Published in
Objects
Tagged under
This article demonstrates how to detect whether an Excel document is password protected or not using Spire.XLS for Java.
import com.spire.xls.Workbook;
public class DetectProtectedOrNot {
public static void main(String[] args) {
//Get the file path
String filePath= "C:\\Users\\Administrator\\Desktop\\sample.xlsx";
//Detect whether the workbook is password protected or not
Boolean isProtected = Workbook.bookIsPasswordProtected(filePath);
//Print results
if (isProtected) {
System.out.print("The document is password protected.");
}
else {
System.out.print("The document is not protected.");
}
}
}

Published in
Security
Tagged under
This article will demonstrate how to use Spire.Presentaion for Java to remove text watermark and image watermark from the presentation slides.
Firstly, view the sample PowerPoint document with text and image watermark:

import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
public class removeTextOrImageWatermark {
public static void main(String[] args) throws Exception {
//Load the sample document
Presentation presentation = new Presentation();
presentation.loadFromFile("Sample.pptx");
//Remove text watermark by removing the shape which contains the string "E-iceblue".
for (int i = 0; i < presentation.getSlides().getCount(); i++)
{
for (int j = 0; j < presentation.getSlides().get(i).getShapes().getCount(); j++)
{
if (presentation.getSlides().get(i).getShapes().get(j) instanceof IAutoShape)
{
IAutoShape shape = (IAutoShape)presentation.getSlides().get(i).getShapes().get(j);
if (shape.getTextFrame().getText().contains("E-iceblue"))
{
presentation.getSlides().get(i).getShapes().remove(shape);
}
}
}
}
//Remove image watermark
for (int i = 0; i < presentation.getSlides().getCount(); i++)
{
presentation.getSlides().get(i).getSlideBackground().getFill().setFillType(FillFormatType.NONE);
}
//Save to file.
presentation.saveToFile("removeTextOrImageWatermark.pptx";, FileFormat.PPTX_2013);
}
}
Effective screenshot after removing text or image watermark:

Published in
Watermark
Tagged under