dev-resources.site
for different kinds of informations.
Java add image and text header/footer to Excel
Published at
2/17/2020
Categories
header
footer
image
text
Author
eiceblue
Author
8 person written this
eiceblue
open
Excel header and footer gives additional information of a spreadsheet. And it can be in text and image. By default, the headers or footers on odd and even pages are the same. We could also set different heard footer for odd and even pages. This article will show you how to insert header and footer to Excel worksheet in Java applications from the following three parts:
Add image header to Excel
Add text footer to Excel
Add different header footer for Odd and Even pages
Add image header to Excel
import com.spire.xls.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
public class ImageHeader {
public static void main(String[] args) throws IOException {
String imageFile = "logo.png";
//Create a workbook and load a file
Workbook workbook = new Workbook();
//Get the first sheet
Worksheet worksheet = workbook.getWorksheets().get(0);
//Load an image from disk
BufferedImage image = ImageIO.read( new File(imageFile));
//Set the image header
worksheet.getPageSetup().setLeftHeaderImage(image);
worksheet.getPageSetup().setLeftHeader("&G");
//Set the view mode as layout
worksheet.setViewMode(ViewMode.Layout);
//Save the document to file
workbook.saveToFile("output/ImageHeader.xlsx", ExcelVersion.Version2010);
}
}
Effective screenshot of image header:
Add text footer to Excel
import com.spire.xls.*;
public class TextFooter {
public static void main(String[] args) {
//Create a workbook and load a file
Workbook workbook = new Workbook();
//Get the first sheet
Worksheet worksheet = workbook.getWorksheets().get(0);
//Set center footer
worksheet.getPageSetup().setCenterFooter("Spire.XLS for Java");
//Set the view mode as layout
worksheet.setViewMode(ViewMode.Layout);
//Save the document to file
workbook.saveToFile("output/TextFooter.xlsx", ExcelVersion.Version2010);
}
}
Effective screenshot of text footer on Excel:
Add different header and footer for Odd and Even pages:
import com.spire.xls.*;
public class HeaderFooter {
public static void main(String[] args) {
//Create a workbook and load a file
Workbook workbook = new Workbook();
//Get the first sheet
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getCellRange("A1").setText("Page 1");
worksheet.getCellRange("J1").setText("Page 2");
//Set different header footer for Odd and Even pages
worksheet.getPageSetup().setDifferentOddEven((byte)1);
//Set the header footer with font, size, bold and color
worksheet.getPageSetup().setOddHeaderString( "&\"Arial\"&12&B&KFFC000 Odd_Header");
worksheet.getPageSetup().setOddFooterString ( "&\"Arial\"&12&B&KFFC000 Odd_Footer");
worksheet.getPageSetup().setEvenHeaderString ( "&\"Arial\"&12&B&KFF0000 Even_Header");
worksheet.getPageSetup().setEvenFooterString ( "&\"Arial\"&12&B&KFF0000 Even_Footer");
//Set the view mode as layout
worksheet.setViewMode(ViewMode.Layout);
//Save the document to file
workbook.saveToFile("output/Different.xlsx", ExcelVersion.Version2010);
}
}
footer Article's
24 articles in total
Responsive Footer using React with Tailwind CSS and React Icons
read article
Comment ajouter un en-tรชte et un pied de page ร Word avec Python
read article
Understanding Word Header and Footer: Professional Advice for java developers
read article
Java-How to Add or Remove Header and Footer in Word documents
read article
๐ฅResponsive Footer Section using Flexbox | HTML CSS๐
read article
How to create header/footer (using HTML) in each page
read article
Help: Same nav and footer in the whole portfolio.
read article
HTML tags | footer
read article
[Java] Add Different Headers/Footers for Odd and Even Pages in Word
read article
Insert Header and Footer to Word using Java
read article
Keep footer at bottom of page - using flexbox
read article
Fix the footer at the bottom of your web page
read article
Footer bottom in GastbyJS
read article
Java add image and text header/footer to Excel
currently reading
Rounded Curved Footer Using Bootstrap 4
read article
Automating the Date On Your Footer.
read article
Add Header and Footer to an Existing PDF Document in Java
read article
Sticky Footer with Flexbox
read article
Sticky Footer in GatsbyJS using Flexbox
read article
Keeping the Footer at the Bottom with CSS-Grid
read article
Keeping the footer at the bottom with CSS Flexbox
read article
How to style footer semantically correct?
read article
Add Headers and Footers to Word Document in Java
read article
The curious case of the infinite page with a footer
read article
Featured ones: