*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class Alignment
-{
- public static void main(String[] args)
- throws IOException
- {
+public class Alignment {
+ public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
- HSSFRow row = sheet.createRow((short) 2);
- createCell(wb, row, (short) 0, HSSFCellStyle.ALIGN_CENTER);
- createCell(wb, row, (short) 1, HSSFCellStyle.ALIGN_CENTER_SELECTION);
- createCell(wb, row, (short) 2, HSSFCellStyle.ALIGN_FILL);
- createCell(wb, row, (short) 3, HSSFCellStyle.ALIGN_GENERAL);
- createCell(wb, row, (short) 4, HSSFCellStyle.ALIGN_JUSTIFY);
- createCell(wb, row, (short) 5, HSSFCellStyle.ALIGN_LEFT);
- createCell(wb, row, (short) 6, HSSFCellStyle.ALIGN_RIGHT);
+ HSSFRow row = sheet.createRow(2);
+ createCell(wb, row, 0, HSSFCellStyle.ALIGN_CENTER);
+ createCell(wb, row, 1, HSSFCellStyle.ALIGN_CENTER_SELECTION);
+ createCell(wb, row, 2, HSSFCellStyle.ALIGN_FILL);
+ createCell(wb, row, 3, HSSFCellStyle.ALIGN_GENERAL);
+ createCell(wb, row, 4, HSSFCellStyle.ALIGN_JUSTIFY);
+ createCell(wb, row, 5, HSSFCellStyle.ALIGN_LEFT);
+ createCell(wb, row, 6, HSSFCellStyle.ALIGN_RIGHT);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
-
}
/**
* @param column the column number to create the cell in
* @param align the alignment for the cell.
*/
- private static void createCell(HSSFWorkbook wb, HSSFRow row, short column, short align)
- {
+ private static void createCell(HSSFWorkbook wb, HSSFRow row, int column, int align) {
HSSFCell cell = row.createCell(column);
cell.setCellValue("Align It");
HSSFCellStyle cellStyle = wb.createCellStyle();
- cellStyle.setAlignment(align);
+ cellStyle.setAlignment((short)align);
cell.setCellStyle(cellStyle);
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
* @author Glen Stampoultzis (glens at apache.org)
* @author Andrew Oliver (acoliver at apache.org)
*/
-public class BigExample
-{
- public static void main(String[] args)
- throws IOException
- {
- short rownum;
+public class BigExample {
+ public static void main(String[] args) throws IOException {
+ int rownum;
// create a new file
FileOutputStream out = new FileOutputStream("workbook.xls");
//set font 1 to 12 point type
f.setFontHeightInPoints((short) 12);
//make it red
- f.setColor((short) HSSFColor.RED.index);
+ f.setColor(HSSFColor.RED.index);
// make it bold
//arial is the default font
f.setBoldweight(f.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);
+ f2.setColor(HSSFColor.WHITE.index);
//make it bold
f2.setBoldweight(f2.BOLDWEIGHT_BOLD);
//set a thin border
cs2.setBorderBottom(cs2.BORDER_THIN);
//fill w fg fill color
- cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
+ cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
// set foreground fill to red
- cs2.setFillForegroundColor((short) HSSFColor.RED.index);
+ cs2.setFillForegroundColor(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++)
+ for (rownum = 0; rownum < 300; rownum++)
{
// create a row
r = s.createRow(rownum);
//r.setRowNum(( short ) rownum);
// create 50 cells (0-49) (the += 2 becomes apparent later
- for (short cellnum = (short) 0; cellnum < 50; cellnum += 2)
+ for (int cellnum = 0; cellnum < 50; cellnum += 2)
{
// create a numeric cell
c = r.createCell(cellnum);
}
// create a string cell (see why += 2 in the
- c = r.createCell((short) (cellnum + 1));
+ c = r.createCell(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)));
+ s.setColumnWidth(cellnum + 1, (int)((50 * 8) / ((double) 1 / 20)));
// on every other row
if ((rownum % 2) == 0)
cs3.setBorderBottom(cs3.BORDER_THICK);
//create 50 cells
- for (short cellnum = (short) 0; cellnum < 50; cellnum++)
- {
+ for (int cellnum =0; cellnum < 50; cellnum++) {
//create a blank type cell (no value)
c = r.createCell(cellnum);
// set it to the thick black border style
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class Borders
-{
- public static void main(String[] args)
- throws IOException
- {
+public class Borders {
+ public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
- HSSFRow row = sheet.createRow((short) 1);
+ HSSFRow row = sheet.createRow(1);
// Create a cell and put a value in it.
- HSSFCell cell = row.createCell((short) 1);
+ HSSFCell cell = row.createCell(1);
cell.setCellValue(4);
// Style the cell with borders all around.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
HSSFPatriarch patr = sheet.createDrawingPatriarch();
//create a cell in row 3
- HSSFCell cell1 = sheet.createRow(3).createCell((short)1);
+ HSSFCell cell1 = sheet.createRow(3).createCell(1);
cell1.setCellValue(new HSSFRichTextString("Hello, World"));
//anchor defines size and position of the comment in worksheet
cell1.setCellComment(comment1);
//create another cell in row 6
- HSSFCell cell2 = sheet.createRow(6).createCell((short)1);
+ HSSFCell cell2 = sheet.createRow(6).createCell(1);
cell2.setCellValue(36.6);
/**
* The second way to assign comment to a cell is to implicitly specify its row and column.
* Note, it is possible to set row and column of a non-existing cell.
- * It works, the commnet is visible.
+ * It works, the comment is visible.
*/
comment2.setRow(6);
comment2.setColumn((short)1);
FileOutputStream out = new FileOutputStream("poi_comment.xls");
wb.write(out);
out.close();
-
-
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
import java.io.IOException;
import java.util.Date;
-public class CellTypes
-{
- public static void main(String[] args)
- throws IOException
- {
+public class CellTypes {
+ public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
- HSSFRow row = sheet.createRow((short)2);
- row.createCell((short) 0).setCellValue(1.1);
- row.createCell((short) 1).setCellValue(new Date());
- row.createCell((short) 2).setCellValue("a string");
- row.createCell((short) 3).setCellValue(true);
- row.createCell((short) 4).setCellType(HSSFCell.CELL_TYPE_ERROR);
+ HSSFRow row = sheet.createRow(2);
+ row.createCell(0).setCellValue(1.1);
+ row.createCell(1).setCellValue(new Date());
+ row.createCell(2).setCellValue("a string");
+ row.createCell(3).setCellValue(true);
+ row.createCell(4).setCellType(HSSFCell.CELL_TYPE_ERROR);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class CreateCells
-{
- public static void main(String[] args)
- throws IOException
- {
+public class CreateCells {
+ public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
- HSSFRow row = sheet.createRow((short)0);
+ HSSFRow row = sheet.createRow(0);
// Create a cell and put a value in it.
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellValue(1);
// Or do it on one line.
- row.createCell((short)1).setCellValue(1.2);
- row.createCell((short)2).setCellValue("This is a string");
- row.createCell((short)3).setCellValue(true);
+ row.createCell(1).setCellValue(1.2);
+ row.createCell(2).setCellValue("This is a string");
+ row.createCell(3).setCellValue(true);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class CreateDateCells
-{
- public static void main(String[] args)
- throws IOException
- {
+public class CreateDateCells {
+ public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
- HSSFRow row = sheet.createRow((short)0);
+ HSSFRow row = sheet.createRow(0);
// Create a cell and put a date value in it. The first cell is not styled as a date.
- HSSFCell cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellValue(new Date());
// we style the second cell as a date (and time). It is important to create a new cell style from the workbook
// otherwise you can end up modifying the built in style and effecting not only this cell but other cells.
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
- cell = row.createCell((short)1);
+ cell = row.createCell(1);
cell.setCellValue(new Date());
cell.setCellStyle(cellStyle);
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
-
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class FrillsAndFills
-{
- public static void main(String[] args)
- throws IOException
- {
+public class FrillsAndFills {
+ public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
- HSSFRow row = sheet.createRow((short) 1);
+ HSSFRow row = sheet.createRow(1);
// Aqua background
HSSFCellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(HSSFColor.AQUA.index);
style.setFillPattern(HSSFCellStyle.BIG_SPOTS);
- HSSFCell cell = row.createCell((short) 1);
+ HSSFCell cell = row.createCell(1);
cell.setCellValue("X");
cell.setCellStyle(style);
style = wb.createCellStyle();
style.setFillForegroundColor(HSSFColor.ORANGE.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
- cell = row.createCell((short) 2);
+ cell = row.createCell(2);
cell.setCellValue("X");
cell.setCellStyle(style);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
import java.io.IOException;
/**
- * Test if hyperlink formula, with url that got more than 127 charaters, works
+ * Test if hyperlink formula, with url that got more than 127 characters, works
*
* @author Bernard Chesnoy
*/
-public class HyperlinkFormula
-{
- public static void main(String[] args)
- throws IOException
- {
- HSSFCell cell;
-
- HSSFWorkbook wb = new HSSFWorkbook();
+public class HyperlinkFormula {
+ public static void main(String[] args) throws IOException {
+ HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
- HSSFRow row = sheet.createRow((short) 0);
+ HSSFRow row = sheet.createRow(0);
- cell = row.createCell((short)0);
+ HSSFCell cell = row.createCell(0);
cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula("HYPERLINK(\"http://127.0.0.1:8080/toto/truc/index.html?test=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"test\")");
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
-
}
}
-\r
/* ====================================================================\r
Licensed to the Apache Software Foundation (ASF) under one or more\r
contributor license agreements. See the NOTICE file distributed with\r
HSSFWorkbook wb = new HSSFWorkbook();\r
\r
//cell style for hyperlinks\r
- //by default hypelrinks are blue and underlined\r
+ //by default hyperlinks are blue and underlined\r
HSSFCellStyle hlink_style = wb.createCellStyle();\r
HSSFFont hlink_font = wb.createFont();\r
hlink_font.setUnderline(HSSFFont.U_SINGLE);\r
HSSFSheet sheet = wb.createSheet("Hyperlinks");\r
\r
//URL\r
- cell = sheet.createRow(0).createCell((short)0);\r
+ cell = sheet.createRow(0).createCell(0);\r
cell.setCellValue("URL Link");\r
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);\r
link.setAddress("http://poi.apache.org/");\r
cell.setCellStyle(hlink_style);\r
\r
//link to a file in the current directory\r
- cell = sheet.createRow(1).createCell((short)0);\r
+ cell = sheet.createRow(1).createCell(0);\r
cell.setCellValue("File Link");\r
link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);\r
link.setAddress("link1.xls");\r
cell.setCellStyle(hlink_style);\r
\r
//e-mail link\r
- cell = sheet.createRow(2).createCell((short)0);\r
+ cell = sheet.createRow(2).createCell(0);\r
cell.setCellValue("Email Link");\r
link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);\r
//note, if subject contains white spaces, make sure they are url-encoded\r
\r
//create a target sheet and cell\r
HSSFSheet sheet2 = wb.createSheet("Target Sheet");\r
- sheet2.createRow(0).createCell((short)0).setCellValue("Target Cell");\r
+ sheet2.createRow(0).createCell(0).setCellValue("Target Cell");\r
\r
- cell = sheet.createRow(3).createCell((short)0);\r
+ cell = sheet.createRow(3).createCell(0);\r
cell.setCellValue("Worksheet Link");\r
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);\r
link.setAddress("'Target Sheet'!A1");\r
FileOutputStream out = new FileOutputStream("hssf-links.xls");\r
wb.write(out);\r
out.close();\r
-\r
}\r
}\r
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
-import org.apache.poi.ss.util.Region;
+import org.apache.poi.ss.util.CellRangeAddress;
import java.io.IOException;
import java.io.FileOutputStream;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class MergedCells
-{
- public static void main(String[] args)
- throws IOException
- {
+public class MergedCells {
+ public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
- HSSFRow row = sheet.createRow((short) 1);
- HSSFCell cell = row.createCell((short) 1);
+ HSSFRow row = sheet.createRow(1);
+ HSSFCell cell = row.createCell(1);
cell.setCellValue("This is a test of merging");
- sheet.addMergedRegion(new Region(1,(short)1,1,(short)2));
+ sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
-
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
* @author Glen Stampoultzis (glens at apache.org)
* @author Fauzia Lala <fauzia.lala at wcom.com>
*/
-public class NewLinesInCells
-{
- public static void main( String[] args ) throws IOException
- {
+public class NewLinesInCells {
+ public static void main( String[] args ) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
- HSSFSheet s = wb.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
- HSSFCellStyle cs = wb.createCellStyle();
- HSSFFont f = wb.createFont();
- HSSFFont f2 = wb.createFont();
-
- cs = wb.createCellStyle();
-
- cs.setFont( f2 );
- //Word Wrap MUST be turned on
- cs.setWrapText( true );
-
- r = s.createRow( (short) 2 );
- r.setHeight( (short) 0x349 );
- c = r.createCell( (short) 2 );
- c.setCellType( HSSFCell.CELL_TYPE_STRING );
- c.setCellValue( "Use \n with word wrap on to create a new line" );
- c.setCellStyle( cs );
- s.setColumnWidth( (short) 2, (short) ( ( 50 * 8 ) / ( (double) 1 / 20 ) ) );
-
- FileOutputStream fileOut = new FileOutputStream( "workbook.xls" );
- wb.write( fileOut );
- fileOut.close();
-
+ HSSFSheet s = wb.createSheet();
+ HSSFRow r = null;
+ HSSFCell c = null;
+ HSSFCellStyle cs = wb.createCellStyle();
+ HSSFFont f2 = wb.createFont();
+
+ cs = wb.createCellStyle();
+
+ cs.setFont(f2);
+ // Word Wrap MUST be turned on
+ cs.setWrapText(true);
+
+ r = s.createRow(2);
+ r.setHeight((short) 0x349);
+ c = r.createCell(2);
+ c.setCellType(HSSFCell.CELL_TYPE_STRING);
+ c.setCellValue("Use \n with word wrap on to create a new line");
+ c.setCellStyle(cs);
+ s.setColumnWidth(2, (int) ((50 * 8) / ((double) 1 / 20)));
+
+ FileOutputStream fileOut = new FileOutputStream("workbook.xls");
+ wb.write(fileOut);
+ fileOut.close();
}
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class NewSheet
-{
- public static void main(String[] args)
- throws IOException
- {
+public class NewSheet {
+ public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- HSSFSheet sheet2 = wb.createSheet("second sheet");
+ HSSFSheet sheet2 = wb.createSheet(); // create with default name
+ wb.setSheetName(1, "second sheet"); // setting sheet name later
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class OfficeDrawing
-{
- public static void main(String[] args)
- throws IOException
- {
+public class OfficeDrawing {
+ public static void main(String[] args) throws IOException {
// Create the workbook and sheets.
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
// Create a row and size one of the cells reasonably large.
HSSFRow row = sheet1.createRow(2);
row.setHeight((short) 2800);
- row.createCell( (short)1 );
- sheet1.setColumnWidth((short) 2, (short) 9000);
+ row.createCell(1);
+ sheet1.setColumnWidth(2, 9000);
// Create the drawing patriarch. This is the top level container for
// all shapes.
{
// Create a row and size one of the cells reasonably large.
HSSFRow row = sheet2.createRow(2);
- row.createCell( (short)1 );
+ row.createCell(1);
row.setHeightInPoints(240);
- sheet2.setColumnWidth((short) 2, (short) 9000);
+ sheet2.setColumnWidth(2, 9000);
// Create the drawing patriarch. This is the top level container for
// all shapes. This will clear out any existing shapes for that sheet.
// Create a row and size one of the cells reasonably large
HSSFRow row = sheet3.createRow(2);
row.setHeightInPoints(140);
- row.createCell( (short)1 );
- sheet3.setColumnWidth((short) 2, (short) 9000);
+ row.createCell(1);
+ sheet3.setColumnWidth(2, 9000);
// Create the drawing patriarch. This is the top level container for
// all shapes. This will clear out any existing shapes for that sheet.
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class OfficeDrawingWithGraphics
-{
- public static void main( String[] args ) throws IOException
- {
+public class OfficeDrawingWithGraphics {
+ public static void main( String[] args ) throws IOException {
// Create a workbook with one sheet and size the first three somewhat
// larger so we can fit the chemical structure diagram in.
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet( "my drawing" );
- sheet.setColumnWidth((short)1, (short)(256 * 27));
+ sheet.setColumnWidth(1, 256 * 27);
HSSFRow row1 = sheet.createRow(0);
row1.setHeightInPoints(10 * 15);
HSSFRow row2 = sheet.createRow(1);
// Add some cells so we can test that the anchoring works when we
// sort them.
- row1.createCell((short)0).setCellValue("C");
- row2.createCell((short)0).setCellValue("A");
- row3.createCell((short)0).setCellValue("B");
+ row1.createCell(0).setCellValue("C");
+ row2.createCell(0).setCellValue("A");
+ row3.createCell(0).setCellValue("B");
// Create the top level drawing patriarch.
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 0, (short) 1, 0 );
group = patriarch.createGroup( a );
group.setCoordinates( 0, 0, 320, 276 );
- float verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / (float)Math.abs(group.getY2() - group.getY1());
+ float verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / Math.abs(group.getY2() - group.getY1());
g = new EscherGraphics( group, wb, Color.black, verticalPointsPerPixel );
g2d = new EscherGraphics2d( g );
drawStar( g2d );
a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 1, (short) 1, 1 );
group = patriarch.createGroup( a );
group.setCoordinates( 0, 0, 640, 276 );
- verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / (float)Math.abs(group.getY2() - group.getY1());
+ verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / Math.abs(group.getY2() - group.getY1());
// verticalPixelsPerPoint = (float)Math.abs(group.getY2() - group.getY1()) / a.getAnchorHeightInPoints(sheet);
g = new EscherGraphics( group, wb, Color.black, verticalPointsPerPixel );
g2d = new EscherGraphics2d( g );
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
/**
* Creates outlines.
- *
+ *
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class Outlines
-{
- private Outlines(){}
-
- public static void main(String[] args)
- throws IOException
- {
+public class Outlines {
+ public static void main(String[] args) throws IOException {
createCase1( "outline1.xls" );
System.out.println( "outline1.xls written. Two expanded groups." );
createCase2( "outline2.xls" );
System.out.println( "outline13.xls written. Mixed bag." );
}
- private static void createCase1( String filename ) throws IOException{
+ private static void createCase1(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupColumn( (short)4, (short)7 );
+ sheet1.groupColumn(4, 7);
- for (int row = 0; row < 200; row++)
- {
- HSSFRow r = sheet1.createRow( row );
- for (int column = 0; column < 200; column++)
- {
- HSSFCell c = r.createCell( (short) column );
- c.setCellValue( column );
+ for (int row = 0; row < 200; row++) {
+ HSSFRow r = sheet1.createRow(row);
+ for (int column = 0; column < 200; column++) {
+ HSSFCell c = r.createCell(column);
+ c.setCellValue(column);
}
}
fileOut.close();
}
- private static void createCase2( String filename ) throws IOException{
+ private static void createCase2(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupColumn( (short)2, (short)10 );
- sheet1.groupColumn( (short)4, (short)7 );
- sheet1.setColumnGroupCollapsed( (short)4, true );
+ sheet1.groupColumn(2, 10);
+ sheet1.groupColumn(4, 7);
+ sheet1.setColumnGroupCollapsed(4, true);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
- private static void createCase3( String filename ) throws IOException{
+ private static void createCase3(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupColumn( (short)2, (short)10 );
- sheet1.groupColumn( (short)4, (short)7 );
- sheet1.setColumnGroupCollapsed( (short)4, true );
- sheet1.setColumnGroupCollapsed( (short)2, true );
+ sheet1.groupColumn(2, 10);
+ sheet1.groupColumn(4, 7);
+ sheet1.setColumnGroupCollapsed(4, true);
+ sheet1.setColumnGroupCollapsed(2, true);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
- private static void createCase4( String filename ) throws IOException{
+ private static void createCase4(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupColumn( (short)2, (short)10 );
- sheet1.groupColumn( (short)4, (short)7 );
- sheet1.setColumnGroupCollapsed( (short)4, true );
- sheet1.setColumnGroupCollapsed( (short)2, true );
+ sheet1.groupColumn(2, 10);
+ sheet1.groupColumn(4, 7);
+ sheet1.setColumnGroupCollapsed(4, true);
+ sheet1.setColumnGroupCollapsed(2, true);
- sheet1.setColumnGroupCollapsed( (short)4, false );
+ sheet1.setColumnGroupCollapsed(4, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
- private static void createCase5( String filename ) throws IOException{
+ private static void createCase5(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupColumn( (short)2, (short)10 );
- sheet1.groupColumn( (short)4, (short)7 );
- sheet1.setColumnGroupCollapsed( (short)4, true );
- sheet1.setColumnGroupCollapsed( (short)2, true );
+ sheet1.groupColumn(2, 10);
+ sheet1.groupColumn(4, 7);
+ sheet1.setColumnGroupCollapsed(4, true);
+ sheet1.setColumnGroupCollapsed(2, true);
- sheet1.setColumnGroupCollapsed( (short)4, false );
- sheet1.setColumnGroupCollapsed( (short)3, false );
+ sheet1.setColumnGroupCollapsed(4, false);
+ sheet1.setColumnGroupCollapsed(3, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
- private static void createCase6( String filename ) throws IOException{
+ private static void createCase6(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupColumn( (short)2, (short)10 );
- sheet1.groupColumn( (short)4, (short)10 );
- sheet1.setColumnGroupCollapsed( (short)4, true );
- sheet1.setColumnGroupCollapsed( (short)2, true );
+ sheet1.groupColumn(2, 10);
+ sheet1.groupColumn(4, 10);
+ sheet1.setColumnGroupCollapsed(4, true);
+ sheet1.setColumnGroupCollapsed(2, true);
- sheet1.setColumnGroupCollapsed( (short)3, false );
+ sheet1.setColumnGroupCollapsed(3, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
- private static void createCase7( String filename )
- throws IOException
- {
+ private static void createCase7(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupRow( 5, 14 );
- sheet1.groupRow( 7, 10 );
+ sheet1.groupRow(5, 14);
+ sheet1.groupRow(7, 10);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
- private static void createCase8( String filename )
- throws IOException
- {
+ private static void createCase8(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupRow( 5, 14 );
- sheet1.groupRow( 7, 10 );
- sheet1.setRowGroupCollapsed( 7, true );
+ sheet1.groupRow(5, 14);
+ sheet1.groupRow(7, 10);
+ sheet1.setRowGroupCollapsed(7, true);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
- private static void createCase9( String filename )
- throws IOException
- {
+ private static void createCase9(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupRow( 5, 14 );
- sheet1.groupRow( 7, 10 );
- sheet1.setRowGroupCollapsed( 7, true );
- sheet1.setRowGroupCollapsed( 5, true );
+ sheet1.groupRow(5, 14);
+ sheet1.groupRow(7, 10);
+ sheet1.setRowGroupCollapsed(7, true);
+ sheet1.setRowGroupCollapsed(5, true);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
-
- private static void createCase10( String filename )
- throws IOException
- {
+ private static void createCase10(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupRow( 5, 14 );
- sheet1.groupRow( 7, 10 );
- sheet1.setRowGroupCollapsed( 7, true );
- sheet1.setRowGroupCollapsed( 5, true );
- sheet1.setRowGroupCollapsed( 8, false );
+ sheet1.groupRow(5, 14);
+ sheet1.groupRow(7, 10);
+ sheet1.setRowGroupCollapsed(7, true);
+ sheet1.setRowGroupCollapsed(5, true);
+ sheet1.setRowGroupCollapsed(8, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
- private static void createCase11( String filename )
- throws IOException
- {
+ private static void createCase11(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupRow( 5, 14 );
- sheet1.groupRow( 7, 10 );
- sheet1.setRowGroupCollapsed( 7, true );
- sheet1.setRowGroupCollapsed( 5, true );
- sheet1.setRowGroupCollapsed( 8, false );
- sheet1.setRowGroupCollapsed( 14, false );
+ sheet1.groupRow(5, 14);
+ sheet1.groupRow(7, 10);
+ sheet1.setRowGroupCollapsed(7, true);
+ sheet1.setRowGroupCollapsed(5, true);
+ sheet1.setRowGroupCollapsed(8, false);
+ sheet1.setRowGroupCollapsed(14, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
- private static void createCase12( String filename )
- throws IOException
- {
+ private static void createCase12(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupRow( 5, 14 );
- sheet1.groupRow( 7, 14 );
- sheet1.setRowGroupCollapsed( 7, true );
- sheet1.setRowGroupCollapsed( 5, true );
- sheet1.setRowGroupCollapsed( 6, false );
+ sheet1.groupRow(5, 14);
+ sheet1.groupRow(7, 14);
+ sheet1.setRowGroupCollapsed(7, true);
+ sheet1.setRowGroupCollapsed(5, true);
+ sheet1.setRowGroupCollapsed(6, false);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
- private static void createCase13( String filename )
- throws IOException
- {
+ private static void createCase13(String filename) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
- sheet1.groupRow( 5, 14 );
- sheet1.groupRow( 7, 14 );
- sheet1.groupRow( 16, 19 );
+ sheet1.groupRow(5, 14);
+ sheet1.groupRow(7, 14);
+ sheet1.groupRow(16, 19);
- sheet1.groupColumn( (short)4, (short)7 );
- sheet1.groupColumn( (short)9, (short)12 );
- sheet1.groupColumn( (short)10, (short)11 );
+ sheet1.groupColumn(4, 7);
+ sheet1.groupColumn(9, 12);
+ sheet1.groupColumn(10, 11);
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
}
-
-
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class ReadWriteWorkbook
-{
- public static void main(String[] args)
- throws IOException
- {
+public class ReadWriteWorkbook {
+ public static void main(String[] args) throws IOException {
FileInputStream fileIn = null;
FileOutputStream fileOut = null;
HSSFRow row = sheet.getRow(2);
if (row == null)
row = sheet.createRow(2);
- HSSFCell cell = row.getCell((short)3);
+ HSSFCell cell = row.getCell(3);
if (cell == null)
- cell = row.createCell((short)3);
+ cell = row.createCell(3);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("a test");
// Write the output to a file
fileOut = new FileOutputStream("workbookout.xls");
wb.write(fileOut);
- }
- finally
- {
+ } finally {
if (fileOut != null)
fileOut.close();
if (fileIn != null)
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
import org.apache.poi.hssf.usermodel.*;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import java.io.IOException;
import java.io.FileOutputStream;
-import java.io.FileInputStream;
/**
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class RepeatingRowsAndColumns
-{
- public static void main(String[] args)
- throws IOException
- {
+public class RepeatingRowsAndColumns {
+ public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("first sheet");
- HSSFSheet sheet2 = wb.createSheet("second sheet");
- HSSFSheet sheet3 = wb.createSheet("third sheet");
-
-// POIFSFileSystem fs =
-// new POIFSFileSystem(new FileInputStream("workbook.xls"));
-// HSSFWorkbook wb = new HSSFWorkbook(fs);
-// HSSFSheet sheet1 = wb.getSheetAt(0);
+ wb.createSheet("second sheet");
+ wb.createSheet("third sheet");
HSSFFont boldFont = wb.createFont();
boldFont.setFontHeightInPoints((short)22);
HSSFCellStyle boldStyle = wb.createCellStyle();
boldStyle.setFont(boldFont);
- HSSFRow row = sheet1.createRow((short)1);
- HSSFCell cell = row.createCell((short)0);
+ HSSFRow row = sheet1.createRow(1);
+ HSSFCell cell = row.createCell(0);
cell.setCellValue("This quick brown fox");
cell.setCellStyle(boldStyle);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.usermodel.examples;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class WorkingWithFonts
-{
- public static void main(String[] args)
- throws IOException
- {
+public class WorkingWithFonts {
+ public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
- HSSFRow row = sheet.createRow((short) 1);
+ HSSFRow row = sheet.createRow(1);
// Create a new font and alter it.
HSSFFont font = wb.createFont();
style.setFont(font);
// Create a cell and put a value in it.
- HSSFCell cell = row.createCell((short) 1);
+ HSSFCell cell = row.createCell(1);
cell.setCellValue("This is a test of fonts");
cell.setCellStyle(style);
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
-
}
}
public class HSSF
{
- private String filename = null;
+ private String _filename = null;
- protected HSSFWorkbook hssfworkbook = null;
+ protected HSSFWorkbook _hssfworkbook = null;
/**
* Constructor HSSF - creates an HSSFStream from an InputStream. The HSSFStream
*
*/
- public HSSF(String filename)
- throws IOException
- {
- this.filename = filename;
- POIFSFileSystem fs =
- new POIFSFileSystem(new FileInputStream(filename));
-
- hssfworkbook = new HSSFWorkbook(fs);
-
- // records = RecordFactory.createRecords(stream);
+ public HSSF(String filename) throws IOException {
+ _filename = filename;
+ _hssfworkbook = new HSSFWorkbook(new FileInputStream(filename));
}
/**
public HSSF(String filename, boolean write)
throws IOException
{
- short rownum = 0;
+ int rownum = 0;
FileOutputStream out = new FileOutputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
cs2.setFillForegroundColor(( short ) 0xA);
cs2.setFont(f2);
wb.setSheetName(0, "HSSF Test");
- for (rownum = ( short ) 0; rownum < 300; rownum++)
+ for (rownum = 0; rownum < 300; rownum++)
{
r = s.createRow(rownum);
if ((rownum % 2) == 0)
}
// r.setRowNum(( short ) rownum);
- for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2)
+ for (int cellnum = 0; cellnum < 50; cellnum += 2)
{
c = r.createCell(cellnum, HSSFCell.CELL_TYPE_NUMERIC);
c.setCellValue(rownum * 10000 + cellnum
rownum++;
r = s.createRow(rownum);
cs3.setBorderBottom(HSSFCellStyle.BORDER_THICK);
- for (short cellnum = ( short ) 0; cellnum < 50; cellnum++)
+ for (int cellnum = 0; cellnum < 50; cellnum++)
{
c = r.createCell(cellnum, HSSFCell.CELL_TYPE_BLANK);
public HSSF(String infile, String outfile, boolean write)
throws IOException
{
- this.filename = infile;
+ _filename = infile;
POIFSFileSystem fs =
- new POIFSFileSystem(new FileInputStream(filename));
+ new POIFSFileSystem(new FileInputStream(_filename));
- hssfworkbook = new HSSFWorkbook(fs);
+ _hssfworkbook = new HSSFWorkbook(fs);
// HSSFWorkbook book = hssfstream.getWorkbook();
}
HSSF hssf = new HSSF(args[ 0 ]);
System.out.println("Data dump:\n");
- HSSFWorkbook wb = hssf.hssfworkbook;
+ HSSFWorkbook wb = hssf._hssfworkbook;
for (int k = 0; k < wb.getNumberOfSheets(); k++)
{
for (int r = 0; r < rows; r++)
{
HSSFRow row = sheet.getRow(r);
- int cells = (row != null) ? row.getPhysicalNumberOfCells() : 0;
- if (row != null) {
- System.out.println("\nROW " + row.getRowNum()
- + " has " + cells + " cell(s).");
+ if (row == null) {
+ continue;
}
+ int cells = row.getPhysicalNumberOfCells();
+ System.out.println("\nROW " + row.getRowNum()
+ + " has " + cells + " cell(s).");
for (int c = 0; c < cells; c++)
{
HSSFCell cell = row.getCell(c);
default :
}
System.out.println("CELL col="
- + cell.getCellNum()
+ + cell.getColumnIndex()
+ " VALUE=" + value);
}
}
HSSF hssf = new HSSF(args[ 0 ]);
// HSSFStream hssfstream = hssf.hssfstream;
- HSSFWorkbook wb = hssf.hssfworkbook;
+ HSSFWorkbook wb = hssf._hssfworkbook;
FileOutputStream stream = new FileOutputStream(args[ 1 ]);
// HSSFCell cell = new HSSFCell();
HSSF hssf = new HSSF(args[ 0 ]);
// HSSFStream hssfstream = hssf.hssfstream;
- HSSFWorkbook wb = hssf.hssfworkbook;
+ HSSFWorkbook wb = hssf._hssfworkbook;
FileOutputStream stream = new FileOutputStream(args[ 1 ]);
HSSFSheet sheet = wb.getSheetAt(0);
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-/*
- * TestCellStyle.java
- *
- * Created on December 11, 2001, 5:51 PM
- */
package org.apache.poi.hssf.usermodel;
-import java.io.*;
-
-import java.util.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
-import junit.framework.*;
+import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.util.TempFile;
* @author Andrew C. Oliver
*/
-public class TestCellStyle
- extends TestCase
-{
+public final class TestCellStyle extends TestCase {
private static HSSFWorkbook openSample(String sampleFileName) {
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
}
- /** Creates a new instance of TestCellStyle */
-
- public TestCellStyle(String name)
- {
- super(name);
- }
/**
* TEST NAME: Test Write Sheet Font <P>
* HSSFSheet last row or first row is incorrect. <P>
*
*/
-
- public void testWriteSheetFont()
- throws IOException
- {
+ public void testWriteSheetFont() throws IOException{
File file = TempFile.createTempFile("testWriteSheetFont",
".xls");
FileOutputStream out = new FileOutputStream(file);
fnt.setColor(HSSFFont.COLOR_RED);
fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
cs.setFont(fnt);
- for (short rownum = ( short ) 0; rownum < 100; rownum++)
- {
+ for (int rownum = 0; rownum < 100; rownum++) {
r = s.createRow(rownum);
- // r.setRowNum(( short ) rownum);
- for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2)
- {
+ for (int cellnum = 0; cellnum < 50; cellnum += 2) {
c = r.createCell(cellnum);
c.setCellValue(rownum * 10000 + cellnum
+ ((( double ) rownum / 1000)
/**
* Tests that is creating a file with a date or an calendar works correctly.
*/
- public void testDataStyle()
- throws Exception
- {
+ public void testDataStyle() throws IOException {
File file = TempFile.createTempFile("testWriteSheetStyleDate",
".xls");
FileOutputStream out = new FileOutputStream(file);
assertEquals("LAST ROW ", 0, s.getLastRowNum());
assertEquals("FIRST ROW ", 0, s.getFirstRowNum());
-
}
public void testHashEquals() {
* HSSFSheet last row or first row is incorrect. <P>
*
*/
-
- public void testWriteSheetStyle()
- throws IOException
- {
+ public void testWriteSheetStyle() throws IOException {
File file = TempFile.createTempFile("testWriteSheetStyle",
".xls");
FileOutputStream out = new FileOutputStream(file);
cs2.setFillForegroundColor(( short ) 0x0);
cs2.setFillPattern(( short ) 1);
cs2.setFont(fnt);
- for (short rownum = ( short ) 0; rownum < 100; rownum++)
- {
+ for (int rownum = 0; rownum < 100; rownum++) {
r = s.createRow(rownum);
- // r.setRowNum(( short ) rownum);
- for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2)
- {
+ for (int cellnum = 0; cellnum < 50; cellnum += 2) {
c = r.createCell(cellnum);
c.setCellValue(rownum * 10000 + cellnum
+ ((( double ) rownum / 1000)
sanityChecker.checkHSSFWorkbook(wb);
assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
-
- // assert((s.getLastRowNum() == 99));
}
/**
* Cloning one HSSFCellStyle onto Another, same
* HSSFWorkbook
*/
- public void testCloneStyleSameWB() throws Exception {
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFFont fnt = wb.createFont();
- fnt.setFontName("TestingFont");
- assertEquals(5, wb.getNumberOfFonts());
-
- HSSFCellStyle orig = wb.createCellStyle();
- orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
- orig.setFont(fnt);
- orig.setDataFormat((short)18);
-
- assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment());
- assertTrue(fnt == orig.getFont(wb));
- assertTrue(18 == orig.getDataFormat());
-
- HSSFCellStyle clone = wb.createCellStyle();
- assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
- assertFalse(fnt == clone.getFont(wb));
- assertFalse(18 == clone.getDataFormat());
-
- clone.cloneStyleFrom(orig);
- assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
- assertTrue(fnt == clone.getFont(wb));
- assertTrue(18 == clone.getDataFormat());
- assertEquals(5, wb.getNumberOfFonts());
+ public void testCloneStyleSameWB() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFFont fnt = wb.createFont();
+ fnt.setFontName("TestingFont");
+ assertEquals(5, wb.getNumberOfFonts());
+
+ HSSFCellStyle orig = wb.createCellStyle();
+ orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
+ orig.setFont(fnt);
+ orig.setDataFormat((short)18);
+
+ assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment());
+ assertTrue(fnt == orig.getFont(wb));
+ assertTrue(18 == orig.getDataFormat());
+
+ HSSFCellStyle clone = wb.createCellStyle();
+ assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
+ assertFalse(fnt == clone.getFont(wb));
+ assertFalse(18 == clone.getDataFormat());
+
+ clone.cloneStyleFrom(orig);
+ assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
+ assertTrue(fnt == clone.getFont(wb));
+ assertTrue(18 == clone.getDataFormat());
+ assertEquals(5, wb.getNumberOfFonts());
}
/**
* Cloning one HSSFCellStyle onto Another, across
* two different HSSFWorkbooks
*/
- public void testCloneStyleDiffWB() throws Exception {
- HSSFWorkbook wbOrig = new HSSFWorkbook();
-
- HSSFFont fnt = wbOrig.createFont();
- fnt.setFontName("TestingFont");
- assertEquals(5, wbOrig.getNumberOfFonts());
-
- HSSFDataFormat fmt = wbOrig.createDataFormat();
- fmt.getFormat("MadeUpOne");
- fmt.getFormat("MadeUpTwo");
-
- HSSFCellStyle orig = wbOrig.createCellStyle();
- orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
- orig.setFont(fnt);
- orig.setDataFormat(fmt.getFormat("Test##"));
-
- assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment());
- assertTrue(fnt == orig.getFont(wbOrig));
- assertTrue(fmt.getFormat("Test##") == orig.getDataFormat());
-
- // Now a style on another workbook
- HSSFWorkbook wbClone = new HSSFWorkbook();
- assertEquals(4, wbClone.getNumberOfFonts());
- HSSFDataFormat fmtClone = wbClone.createDataFormat();
-
- HSSFCellStyle clone = wbClone.createCellStyle();
- assertEquals(4, wbClone.getNumberOfFonts());
-
- assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
- assertFalse("TestingFont" == clone.getFont(wbClone).getFontName());
-
- clone.cloneStyleFrom(orig);
- assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
- assertTrue("TestingFont" == clone.getFont(wbClone).getFontName());
- assertTrue(fmtClone.getFormat("Test##") == clone.getDataFormat());
- assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##"));
- assertEquals(5, wbClone.getNumberOfFonts());
+ public void testCloneStyleDiffWB() {
+ HSSFWorkbook wbOrig = new HSSFWorkbook();
+
+ HSSFFont fnt = wbOrig.createFont();
+ fnt.setFontName("TestingFont");
+ assertEquals(5, wbOrig.getNumberOfFonts());
+
+ HSSFDataFormat fmt = wbOrig.createDataFormat();
+ fmt.getFormat("MadeUpOne");
+ fmt.getFormat("MadeUpTwo");
+
+ HSSFCellStyle orig = wbOrig.createCellStyle();
+ orig.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
+ orig.setFont(fnt);
+ orig.setDataFormat(fmt.getFormat("Test##"));
+
+ assertTrue(HSSFCellStyle.ALIGN_RIGHT == orig.getAlignment());
+ assertTrue(fnt == orig.getFont(wbOrig));
+ assertTrue(fmt.getFormat("Test##") == orig.getDataFormat());
+
+ // Now a style on another workbook
+ HSSFWorkbook wbClone = new HSSFWorkbook();
+ assertEquals(4, wbClone.getNumberOfFonts());
+ HSSFDataFormat fmtClone = wbClone.createDataFormat();
+
+ HSSFCellStyle clone = wbClone.createCellStyle();
+ assertEquals(4, wbClone.getNumberOfFonts());
+
+ assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
+ assertFalse("TestingFont" == clone.getFont(wbClone).getFontName());
+
+ clone.cloneStyleFrom(orig);
+ assertTrue(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
+ assertTrue("TestingFont" == clone.getFont(wbClone).getFontName());
+ assertTrue(fmtClone.getFormat("Test##") == clone.getDataFormat());
+ assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##"));
+ assertEquals(5, wbClone.getNumberOfFonts());
}
- public void testStyleNames() throws Exception {
+ public void testStyleNames() {
HSSFWorkbook wb = openSample("WithExtendedStyles.xls");
- HSSFSheet s = wb.getSheetAt(0);
- HSSFCell c1 = s.getRow(0).getCell(0);
- HSSFCell c2 = s.getRow(1).getCell(0);
- HSSFCell c3 = s.getRow(2).getCell(0);
-
- HSSFCellStyle cs1 = c1.getCellStyle();
- HSSFCellStyle cs2 = c2.getCellStyle();
- HSSFCellStyle cs3 = c3.getCellStyle();
-
- assertNotNull(cs1);
- assertNotNull(cs2);
- assertNotNull(cs3);
-
- // Check we got the styles we'd expect
- assertEquals(10, cs1.getFont(wb).getFontHeightInPoints());
- assertEquals(9, cs2.getFont(wb).getFontHeightInPoints());
- assertEquals(12, cs3.getFont(wb).getFontHeightInPoints());
-
- assertEquals(15, cs1.getIndex());
- assertEquals(23, cs2.getIndex());
- assertEquals(24, cs3.getIndex());
-
- assertNull(cs1.getParentStyle());
- assertNotNull(cs2.getParentStyle());
- assertNotNull(cs3.getParentStyle());
-
- assertEquals(21, cs2.getParentStyle().getIndex());
- assertEquals(22, cs3.getParentStyle().getIndex());
-
- // Now check we can get style records for
- // the parent ones
- assertNull(wb.getWorkbook().getStyleRecord(15));
- assertNull(wb.getWorkbook().getStyleRecord(23));
- assertNull(wb.getWorkbook().getStyleRecord(24));
-
- assertNotNull(wb.getWorkbook().getStyleRecord(21));
- assertNotNull(wb.getWorkbook().getStyleRecord(22));
-
- // Now check the style names
- assertEquals(null, cs1.getUserStyleName());
- assertEquals(null, cs2.getUserStyleName());
- assertEquals(null, cs3.getUserStyleName());
- assertEquals("style1", cs2.getParentStyle().getUserStyleName());
- assertEquals("style2", cs3.getParentStyle().getUserStyleName());
- }
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.hssf.usermodel.HSSFCellStyle");
- junit.textui.TestRunner.run(TestCellStyle.class);
+ HSSFSheet s = wb.getSheetAt(0);
+ HSSFCell c1 = s.getRow(0).getCell(0);
+ HSSFCell c2 = s.getRow(1).getCell(0);
+ HSSFCell c3 = s.getRow(2).getCell(0);
+
+ HSSFCellStyle cs1 = c1.getCellStyle();
+ HSSFCellStyle cs2 = c2.getCellStyle();
+ HSSFCellStyle cs3 = c3.getCellStyle();
+
+ assertNotNull(cs1);
+ assertNotNull(cs2);
+ assertNotNull(cs3);
+
+ // Check we got the styles we'd expect
+ assertEquals(10, cs1.getFont(wb).getFontHeightInPoints());
+ assertEquals(9, cs2.getFont(wb).getFontHeightInPoints());
+ assertEquals(12, cs3.getFont(wb).getFontHeightInPoints());
+
+ assertEquals(15, cs1.getIndex());
+ assertEquals(23, cs2.getIndex());
+ assertEquals(24, cs3.getIndex());
+
+ assertNull(cs1.getParentStyle());
+ assertNotNull(cs2.getParentStyle());
+ assertNotNull(cs3.getParentStyle());
+
+ assertEquals(21, cs2.getParentStyle().getIndex());
+ assertEquals(22, cs3.getParentStyle().getIndex());
+
+ // Now check we can get style records for
+ // the parent ones
+ assertNull(wb.getWorkbook().getStyleRecord(15));
+ assertNull(wb.getWorkbook().getStyleRecord(23));
+ assertNull(wb.getWorkbook().getStyleRecord(24));
+
+ assertNotNull(wb.getWorkbook().getStyleRecord(21));
+ assertNotNull(wb.getWorkbook().getStyleRecord(22));
+
+ // Now check the style names
+ assertEquals(null, cs1.getUserStyleName());
+ assertEquals(null, cs2.getUserStyleName());
+ assertEquals(null, cs3.getUserStyleName());
+ assertEquals("style1", cs2.getParentStyle().getUserStyleName());
+ assertEquals("style2", cs3.getParentStyle().getUserStyleName());
}
}
limitations under the License.
==================================================================== */
-
-/*
- * TestRowStyle.java
- *
- * Created on May 20, 2005
- */
package org.apache.poi.hssf.usermodel;
-import java.io.IOException;
-
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.util.TempFile;
/**
* Class to test row styling functionality
*
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*/
-
-public class TestRowStyle
- extends TestCase
-{
-
- /** Creates a new instance of TestCellStyle */
-
- public TestRowStyle(String name)
- {
- super(name);
- }
+public final class TestRowStyle extends TestCase {
/**
* TEST NAME: Test Write Sheet Font <P>
* HSSFSheet last row or first row is incorrect. <P>
*
*/
-
- public void testWriteSheetFont()
- throws IOException
- {
+ public void testWriteSheetFont() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
- HSSFCell c = null;
HSSFFont fnt = wb.createFont();
HSSFCellStyle cs = wb.createCellStyle();
fnt.setColor(HSSFFont.COLOR_RED);
fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
cs.setFont(fnt);
- for (short rownum = ( short ) 0; rownum < 100; rownum++)
+ for (int rownum = 0; rownum < 100; rownum++)
{
r = s.createRow(rownum);
r.setRowStyle(cs);
/**
* Tests that is creating a file with a date or an calendar works correctly.
*/
- public void testDataStyle()
- throws Exception
- {
+ public void testDataStyle() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFCellStyle cs = wb.createCellStyle();
- HSSFRow row = s.createRow((short)0);
+ HSSFRow row = s.createRow(0);
// with Date:
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
// with Calendar:
- row = s.createRow((short)1);
+ row = s.createRow(1);
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
row.setRowStyle(cs);
row.createCell(0);
* HSSFSheet last row or first row is incorrect. <P>
*
*/
-
- public void testWriteSheetStyle()
- throws IOException
- {
+ public void testWriteSheetStyle() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
cs2.setFillForegroundColor(( short ) 0x0);
cs2.setFillPattern(( short ) 1);
cs2.setFont(fnt);
- for (short rownum = ( short ) 0; rownum < 100; rownum++)
+ for (int rownum = 0; rownum < 100; rownum++)
{
r = s.createRow(rownum);
r.setRowStyle(cs);
s = wb.getSheetAt(0);
assertNotNull("Sheet is not null", s);
- for (short rownum = ( short ) 0; rownum < 100; rownum++)
+ for (int rownum = 0; rownum < 100; rownum++)
{
r = s.getRow(rownum);
assertNotNull("Row is not null", r);
assertEquals("FillPattern for row: ", cs2.getFillPattern(), (short) 0x1);
}
}
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.hssf.usermodel.HSSFCellStyle");
- junit.textui.TestRunner.run(TestCellStyle.class);
- }
}