HSSF WORKSHEET FORMATTING
I am using the following code in my jsp to import thr o/p to excel on the server.
<%
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("sheet"); %>
<% int i=1; %>
<% try{
HSSFRow row = sheet.createRow((short)i);
row.createCell((short)0).setCellValue("BIN");
row.createCell((short)1).setCellValue("NAME");
row.createCell((short)2).setCellValue("NAME");
row.createCell((short)3).setCellValue("NAME");
row.createCell((short)4).setCellValue("NAME");
FileOutputStream fileOut = new FileOutputStream("c:\\Filename");
wb.write(fileOut);
fileOut.close();
}
catch ( Exception ex ){
} %>
It works fine but I want to change the properties of the cols in excel through my code.
properties:
text should be bold
it should be aligned right.
PLZZZZZZ HELP
View Answers
December 26, 2009 at 2:25 PM
Hi Friend,
Use font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD)method of HSSFFont class to bold the text and cellStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT) method of HSSFCellStyle class.
Try the following code:
<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCellStyle"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFFont"%>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%
try{
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow row = sheet.createRow((short) 1);
HSSFCell cell = row.createCell((short) 1);
cell.setCellValue("Hello World");
HSSFFont font = hwb.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle cellStyle = hwb.createCellStyle();
cellStyle.setFont(font);
cell.setCellStyle(cellStyle);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
FileOutputStream fileOut = new FileOutputStream
("c:\\fontsExcel.xls");
hwb.write(fileOut);
fileOut.close();
out.println("Your excel file has been generated");
} catch ( Exception ex ) {
}
%>
For more information, visit the following links:
http://www.roseindia.net/jsp/poi/workingWithFonts.shtmlhttp://www.roseindia.net/jsp/poi/workingAlign.shtmlThanks
Related Tutorials/Questions & Answers:
ModuleNotFoundError: No module named 'worksheet'ModuleNotFoundError: No module named '
worksheet' Hi,
My Python... '
worksheet'
How to remove the ModuleNotFoundError: No module named '
worksheet' error?
Thanks
Hi,
In your python environment you
Advertisements
ModuleNotFoundError: No module named 'worksheet'ModuleNotFoundError: No module named '
worksheet' Hi,
My Python... '
worksheet'
How to remove the ModuleNotFoundError: No module named '
worksheet' error?
Thanks
Hi,
In your python environment you
formatting programformatting program Hi I needs some help with this program on formating can anyone help?The details of the program are stated below, thanks.
This program should be an example of how Java lets
you format numbers and strings
< problem in XSL formatting to generate the output in XML format.
but the data is having HTML
formatting.
So i am...
formatting with out any encoding.
How can we restict the encoding of < with <
and > also behaving as same above.
That to the
formatting has
Formatting numbers in Velocity Templates?Formatting numbers in Velocity Templates? I need to display amount in following formats:
1099 -> 1,099.00
100 -> 100.00
100.251 -> 100.25
10999 -> 10,999.00
1110999 -> 11,10,999.00
Right now I am using
Formatting numbers in Velocity Templates?Formatting numbers in Velocity Templates? I need to display amount in following formats:
1099 -> 1,099.00
100 -> 100.00
100.251 -> 100.25
10999 -> 10,999.00
1110999 -> 11,10,999.00
Right now I am using
Using HSSF 3.5 to READ XLS - Java BeginnersUsing
HSSF 3.5 to READ XLS I just dont seem to get this working. I have tried the examples here on this homepage but they are out of date for 3.5 since they are built on and older relese i cant get them to work.
All i want
Formatting Legend in Chart in Flex4Formatting Legend in Chart in Flex4:
In this section we will discuss the
formatting of the
Legend in the Chart control. You can change the
formatting... property for change
the
formatting of legend in the chart control.
Example
Scanning and Formatting in JavaScanning and
Formatting in Java
In this we will discuss about the Java I/O Scanning and
Formatting.
In the perspective of programming in Java I/O we... provides the two APIs
namely scanner and the
formatting. The scanner
API
Formatting number as per specific locale in javaFormatting number as per specific locale in java Hi,
I am trying to print the number as per locale. I tried below, but it still prints in English locale.
public class loctest {
public static void main(String[] args
Example program to change Date formatting Symbols Example program to change Date
formatting Symbols... such examples. Now you will
learn how we can change the
formatting symbols for date.
In this example of changing the date
formatting symbols
we have used
Formatting and Parsing a Time for a LocaleFormatting and Parsing a Time for a Locale
In this section, you will learn how... for
formatting dates, numbers, messages and
other objects. These classes helps.... For
formatting and parsing the
time, here we have used DateFormat class
Formatting Date for a Locale Example Formatting Date for a Locale Example
This example shows how to format Date using... use for
formatting and parsing dates. It allows for
formatting date into text
Formatting a Number in Exponential NotationFormatting a Number in Exponential Notation
In this section, you will learn how to format a number in Exponential
Notation.
Java has designed several classes for parsing and
formatting the numbers like
DecimalFormat class. This class
Formatting and Parsing a Number for a LocaleFormatting and Parsing a Number for a Locale
In this section, you will learn how to format and parse a number for a
Locale.
Formatting converts a date, time, number, or message from its internal
representation into a string. Parsing
Formatting a Message Containing a NumberFormatting a Message Containing a Number
In this section, you will learn how... that contains a number. The class
MessageFormat provides advanced message
formatting. It allows advanced value
formatting, dependency on Locale and precompilation
Formatting a Message Containing a TimeFormatting a Message Containing a Time
In this section, you will learn how to format a message that contains time.
You can format the message in different... MessageFormat for advanced message
formatting.
It is having some advantage over other
Formatting and Parsing a Date for a LocaleFormatting and Parsing a Date for a Locale
In this section, you will learn how to format and parse a date for a locale.
Java has provide the utility to display the dates in different languages. You
can also format and parse those dates
Formatting a Message Containing a DateFormatting a Message Containing a Date
In this section, you will learn how to format the message containing a date.
Java has also provide a way to format the message either it contains date,
time or number. The class MessageFormat
Formatting and Parsing a Locale-Specific PercentageFormatting and Parsing a Locale-Specific Percentage
In this section, you... characters, we can perform
formatting and parsing. Through the
use of classes, we can.... This class helps in
formatting and parsing numbers for any
locale.
You can
Formatting a Date Using a Custom FormatFormatting a Date Using a Custom Format
In this section, you will learn how to format a date using a custom format.
Java has provide many classes that allow... class which is responsible for
formatting date and time. It uses unquoted letters
Formatting and Parsing Locale-Specific CurrencyFormatting and Parsing Locale-Specific Currency
In this section, you will learn how to format and parse the locale specific
currency.
Through the
formatting, you can translate the binary data into user-readable
textual representation
Formatting the Time Using a Custom FormatFormatting the Time Using a Custom Format
In this section, you will learn how to format the time using a custom format.
Formatting and parsing is now become a simple task. We have so many classes
to format different objects like data
Formatting the out put in NSLog functionYou can easily format the values of int, float, double and long while using the NSLog function.
Here is the example of
formatting int, float, double and long values.
//
// PrintFormat.h
// DataTypes
//
//
#import <
Formatting a Number Using a Custom FormatFormatting a Number Using a Custom Format
In this section, you will learn how to format a number using a custom format.
A number can be formatted in different ways. Java has designed several
classes to format the number. Using
Java Text Tutorials and time
formatting,
number
formatting, parsing, iteration over characters... three main groups
of classes and interfaces:
Iteration over text
Formatting... can give any custom date and time
formatting, message
formatting. You can compare
Formatting and Parsing a Date Using Default FormatsFormatting and Parsing a Date Using Default Formats
In this section, you... for
formatting and parsing dates. These are SHORT, MEDIUM, LONG
and FULL. There is one.... This method gets the date formatter with the given
formatting style. The format
Mysql Date Format Mysql Date Format
Mysql Date Format explains you the way of
formatting Date... for
formatting the date :
SYNTAX:-DATE_FORMAT(date,format)
date
How to format number in Java?Learn about the code of
formatting the number in Java
This tutorial explains... of
formatting the number is to use the DecimalFormat
class. This class is most convenient class for
formatting the number and
provides ways of
formatting DateInterval::formatDateInterval class in PHP
DateInterval::format function is used for
formatting the interval. It returns the format interval.
Description on PHP DateInterval Format
public string DateInterval::format ( string $format
Examples of POI3.0 can use
HSSF if you needed to read or write an
Excel file using... are using the built in format for
formatting
our data in excel sheet
Currency Format Example. In the code given below we are
formatting Currency according to the locale.
Methods... : NumberFormat class provides the functionality for
formatting and parsing currency
Number Format Example. In the code given below we are
formatting number according to the locale...() : NumberFormat class provides the functionality for
formatting and parsing
Get Time Now
Get Time Now
Format is an abstract class that is used for
formatting local-sensitive
information like date, number and message. The Format class derived from
APT Editor
document format that uses "
formatting hints" to transform a plain text...?
A parser analyzes the document and looks for
"
formatting hints"...
formatting, and APT Editor does the rest.
Why choose APT over other formats?ADS