/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2006 Helma Software. All Rights Reserved.
*
* $RCSfile: Chart.js,v $
* $Author$
* $Revision$
* $Date$
*/
/**
* @fileoverview Fields and methods of the helma.Chart prototype
*
* To use this optional module, its repository needs to be added to the
* application, for example by calling app.addRepository('modules/helma/Chart.js')
*/
// take care of any dependencies
app.addRepository('modules/helma/jxl-2.5.7.jar');
/**
* Define the global namespace if not existing
*/
if (!global.helma) {
global.helma = {};
}
/**
* Creates a new instance of helma.Chart
* @class Instances of this class are capable of reading
* Excel spreadsheets and rendering them as XHTML table. Internally
* helma.Chart uses the Java Excel API
* by Andy Khan.
* @param {String} fpath The path to the spreadsheet file
* @param {String} prefix An optional prefix to use for all
* stylesheet classes within the rendered table
* @param {String} sheetName The name of the sheet within the
* spreadsheet file to render. If this argument is omitted, the
* first sheet is rendered.
* @returns A newly created helma.Chart instance.
* @constructor
* @author Tobi Schaefer
*/
helma.Chart = function(fpath, prefix, sheetName) {
var JXLPKG = Packages.jxl.Workbook;
var JXLPKGNAME = "jxl.jar";
var JXLPKGURL = "http://www.andykhan.com/jexcelapi/";
var workbook, file;
try {
file = new java.io.File(fpath);
workbook = JXLPKG.getWorkbook(file);
} catch (e) {
if (e instanceof TypeError == false)
throw(e);
throw("helma.Chart needs " + JXLPKGNAME +
" in lib/ext or application directory " +
"[" + JXLPKGURL + "]");
}
var getCellStyle = function(c) {
if (!c)
return;
var result = new Object();
var format = c.getCellFormat();
var font = format.getFont();
if (font.getBoldWeight() > 400)
result.bold = true;
result.italic = font.isItalic();
result.wrap = format.getWrap();
var type = c.getType();
var align = format.getAlignment().getDescription();
if (align == "right" || type == "Number" || type == "Date")
result.align = "right";
else if (align == "centre")
result.align = "center";
return result;
}
if (sheetName) {
var sheet = workbook.getSheet(sheetName);
} else {
var sheet = workbook.getSheet(0);
}
if (!sheet)
return;
prefix = prefix ? prefix + "_" : "chart_";
/**
* Renders the Excel spreadsheet as XHTML table.
*/
this.render = function() {
res.write('