aboutsummaryrefslogtreecommitdiffstats
path: root/src/documentation/xdocs/hssf
diff options
context:
space:
mode:
authorAndrew C. Oliver <acoliver@apache.org>2002-07-21 03:03:57 +0000
committerAndrew C. Oliver <acoliver@apache.org>2002-07-21 03:03:57 +0000
commit605e028ae56655c3af3a8fe739456ab75b6cebab (patch)
treed77edb790572e9f5051cf6bc06bc7afb01d7f559 /src/documentation/xdocs/hssf
parente960c2f5e3a0040237d5c3575ca6fececa68a558 (diff)
downloadpoi-605e028ae56655c3af3a8fe739456ab75b6cebab.tar.gz
poi-605e028ae56655c3af3a8fe739456ab75b6cebab.zip
from russia with love (LOL)
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10548 #1 PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352795 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/documentation/xdocs/hssf')
-rw-r--r--src/documentation/xdocs/hssf/how-to.xml84
1 files changed, 47 insertions, 37 deletions
diff --git a/src/documentation/xdocs/hssf/how-to.xml b/src/documentation/xdocs/hssf/how-to.xml
index 74b3cc45e9..39aa03ca22 100644
--- a/src/documentation/xdocs/hssf/how-to.xml
+++ b/src/documentation/xdocs/hssf/how-to.xml
@@ -7,6 +7,7 @@
<authors>
<person email="acoliver2@users.sourceforge.net" name="Andrew C. Oliver" id="AO"/>
<person email="glens@apache.org" name="Glen Stampoultzis" id="GJS"/>
+ <person email="sergeikozello@mail.ru" name="Sergei Kozello" id="SK"/>
</authors>
</header>
<body>
@@ -42,7 +43,10 @@
sequence to the workbook. Sheets do not in themselves have a sheet
name (the tab at the bottom); you set
the name associated with a sheet by calling
- HSSFWorkbook.setSheetName(sheetindex,&quot;SheetName&quot;).</p>
+ HSSFWorkbook.setSheetName(sheetindex,&quot;SheetName&quot;,encoding).
+ The name may be in 8bit format (HSSFWorkbook.ENCODING_COMPRESSED_UNICODE)
+ or Unicode (HSSFWorkbook.ENCODING_UTF_16). Default encoding is 8bit per char.
+ </p>
<p>Rows are created by calling createRow(rowNumber) from an existing
instance of HSSFSheet. Only rows that have cell values should be
added to the sheet. To set the row's height, you just call
@@ -98,18 +102,20 @@ HSSFFont f2 = wb.createFont();
//set font 1 to 12 point type
f.setFontHeightInPoints((short) 12);
-//make it red
-f.setColor((short) HSSFColor.RED.index);
+//make it blue
+f.setColor( (short)0xc );
// make it bold
//arial is the default font
-f.setBoldweight(f.BOLDWEIGHT_BOLD);
+f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//set font 2 to 10 point type
f2.setFontHeightInPoints((short) 10);
-//make it the color at palette index 0xf (white)
-f2.setColor((short) HSSFColor.WHITE.index);
+//make it red
+f2.setColor( (short)HSSFFont.COLOR_RED );
//make it bold
-f2.setBoldweight(f2.BOLDWEIGHT_BOLD);
+f2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+
+f2.setStrikeout( true );
//set cell stlye
cs.setFont(f);
@@ -120,16 +126,18 @@ cs.setDataFormat(HSSFDataFormat.getFormat("($#,##0_);[Red]($#,##0)"));
cs2.setBorderBottom(cs2.BORDER_THIN);
//fill w fg fill color
cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
-// set foreground fill to red
-cs2.setFillForegroundColor((short) HSSFColor.RED.index);
// set the font
cs2.setFont(f2);
-// set the sheet name to HSSF Test
-wb.setSheetName(0, "HSSF Test");
-// create a sheet with 300 rows (0-299)
-for (rownum = (short) 0; rownum < 300; rownum++)
+// set the sheet name in Unicode
+wb.setSheetName(0, "\u0422\u0435\u0441\u0442\u043E\u0432\u0430\u044F " +
+ "\u0421\u0442\u0440\u0430\u043D\u0438\u0447\u043A\u0430",
+ HSSFWorkbook.ENCODING_UTF_16 );
+// in case of compressed Unicode
+// wb.setSheetName(0, "HSSF Test", HSSFWorkbook.ENCODING_COMPRESSED_UNICODE );
+// create a sheet with 30 rows (0-29)
+for (rownum = (short) 0; rownum < 30; rownum++)
{
// create a row
r = s.createRow(rownum);
@@ -141,8 +149,8 @@ for (rownum = (short) 0; rownum < 300; rownum++)
}
//r.setRowNum(( short ) rownum);
- // create 50 cells (0-49) (the += 2 becomes apparent later
- for (short cellnum = (short) 0; cellnum < 50; cellnum += 2)
+ // create 10 cells (0-9) (the += 2 becomes apparent later
+ for (short cellnum = (short) 0; cellnum < 10; cellnum += 2)
{
// create a numeric cell
c = r.createCell(cellnum);
@@ -151,29 +159,31 @@ for (rownum = (short) 0; rownum < 300; rownum++)
+ (((double) rownum / 1000)
+ ((double) cellnum / 10000)));
+ String cellValue;
+
+ // create a string cell (see why += 2 in the
+ c = r.createCell((short) (cellnum + 1));
+
// on every other row
if ((rownum % 2) == 0)
{
// set this cell to the first cell style we defined
c.setCellStyle(cs);
+ // set the cell's string value to "Test"
+ c.setEncoding( HSSFCell.ENCODING_COMPRESSED_UNICODE );
+ c.setCellValue( "Test" );
}
-
- // create a string cell (see why += 2 in the
- c = r.createCell((short) (cellnum + 1));
-
- // set the cell's string value to "TEST"
- c.setCellValue("TEST");
- // make this column a bit wider
- s.setColumnWidth((short) (cellnum + 1), (short) ((50 * 8) / ((double) 1 / 20)));
-
- // on every other row
- if ((rownum % 2) == 0)
+ else
{
- // set this to the white on red cell style
- // we defined above
c.setCellStyle(cs2);
+ // set the cell's string value to "\u0422\u0435\u0441\u0442"
+ c.setEncoding( HSSFCell.ENCODING_UTF_16 );
+ c.setCellValue( "\u0422\u0435\u0441\u0442" );
}
+
+ // make this column a bit wider
+ s.setColumnWidth((short) (cellnum + 1), (short) ((50 * 8) / ((double) 1 / 20)));
}
}
@@ -383,21 +393,21 @@ level API (and indirectly the low level support). The main body of
its code is repeated above. To run it:
</p>
<ul>
- <li>download the poi-alpha build and untar it (tar xvzf
- tarball.tar.gz)
- </li>
- <li>set up your classpath as follows:
- <code>export HSSFDIR={wherever you put HSSF's jar files}
+ <li>download the poi-alpha build and untar it (tar xvzf
+ tarball.tar.gz)
+ </li>
+ <li>set up your classpath as follows:
+ <code>export HSSFDIR={wherever you put HSSF's jar files}
export LOG4JDIR={wherever you put LOG4J's jar files}
export CLASSPATH=$CLASSPATH:$HSSFDIR/hssf.jar:$HSSFDIR/poi-poifs.jar:$HSSFDIR/poi-util.jar:$LOG4JDIR/jog4j.jar</code>
- </li><li>type:
- <code>java org.apache.poi.hssf.dev.HSSF ~/myxls.xls write</code></li>
+ </li><li>type:
+ <code>java org.apache.poi.hssf.dev.HSSF ~/myxls.xls write</code></li>
</ul>
<p></p>
<p>This should generate a test sheet in your home directory called <code>&quot;myxls.xls&quot;</code>. </p>
<ul>
- <li>Type:
- <code>java org.apache.poi.hssf.dev.HSSF ~/input.xls output.xls</code>
+ <li>Type:
+ <code>java org.apache.poi.hssf.dev.HSSF ~/input.xls output.xls</code>
<br/>
<br/>
This is the read/write/modify test. It reads in the spreadsheet, modifies a cell, and writes it back out.