Skip navigation links

Package com.hfg.xml.msoffice2003.spreadsheetml

The classes in this package can be used to construct simple Microsoft Office 2003 Excel spreadsheets in an object-oriented fashion.

See: Description

Package com.hfg.xml.msoffice2003.spreadsheetml Description

The classes in this package can be used to construct simple Microsoft Office 2003 Excel spreadsheets in an object-oriented fashion.

Simple example:

      ExcelDoc doc = new ExcelDoc();

      ExcelWorkbook workbook = new ExcelWorkbook();
      doc.setRootNode(workbook);

      // Define some styles and add them to the workbook
      ExcelStyle style = new ExcelStyle("sHeader");
      style.addFont().setColor(HTMLColor.BLUE).setBold();
      style.setBackgroundColor(HTMLColor.GREEN);
      style.addBorder().setPosition(ExcelBorderPosition.Bottom).setLineStyle(ExcelLineStyle.Continuous).setWeight(2);
      style.setHorizontalAlignment(ExcelHorizontalAlign.Center);
      style.setVerticalAlignment(ExcelVerticalAlign.Bottom);
      style.setTextRotation(90);
      workbook.addStyle(style);

      ExcelStyle col1Style = new ExcelStyle("col1Style");
      col1Style.setHorizontalAlignment(ExcelHorizontalAlign.Center);
      workbook.addStyle(col1Style);

      ExcelStyle col2Style = new ExcelStyle("col2Style");
      col2Style.setHorizontalAlignment(ExcelHorizontalAlign.Right);
      col2Style.setNumberFormat(ExcelNumberFormat.Scientific);
      workbook.addStyle(col2Style);

      // Create a new sheet
      ExcelWorksheet sheet = workbook.addWorksheet("Sheet1");
      ExcelTable table = sheet.addTable().setExpandedColumnCount(2);

      table.addColumn().setStyleId("col1Style").setWidth(100);
      table.addColumn().setWidth(200);

      ExcelRow row = table.addRow();

      // Add a row with colum names
      row.addCell().setStyleId("sHeader").setData("Column 1");
      row.addCell().setStyleId("sHeader").setData("Column 2");

      // Add a row of data
      row = table.addRow();
      row.addCell().setStyleId("col1Style").setData(1);
      row.addCell().setStyleId("col2Style").setData(2.03444);

      FileUtil.write(new File("xml_test.xml"), doc.toIndentedXML(0, 3));
   

Skip navigation links

Copyright © 2002-2022 hairyfatguy.com
com.hfg XML/HTML Coding Library
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
J. Alex Taylor, President, Founder, CEO, COO, CFO, CTO, OOPS hairyfatguy.com
jataylor@hairyfatguy.com