Java (481)
This article demonstrates how to adjust the header and footer distance in a Word document using Spire.Doc for Java.
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
public class AdjustHeaderFooterDistance {
public static void main(String[] args){
//Create a Document instance
Document doc = new Document();
//Load a Word document
doc.loadFromFile("Headers and Footers.docx");
//Get the first section
Section section = doc.getSections().get(0);
//Adjust the header distance
section.getPageSetup().setHeaderDistance(100);
//Adjust the footer distance
section.getPageSetup().setFooterDistance(100);
//Save the result document
doc.saveToFile("Output.docx", FileFormat.Docx);
}
}
Screenshot
Header:

Footer:

Published in
Header and Footer
Tagged under
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