Global.helma.Chart (fpath, prefix, sheetName)
Sourcecode in /home/hannes/helma/modules/helma/Chart.js:
33:   helma.Chart = function(fpath, prefix, sheetName) {
34:       var JXLPKG = Packages.jxl.Workbook;
35:       var JXLPKGNAME = "jxl.jar";
36:       var JXLPKGURL = "http://www.andykhan.com/jexcelapi/";
37:   
38:       var workbook, file;
39:       try {
40:           file = new java.io.File(fpath); 
41:           workbook = JXLPKG.getWorkbook(file);
42:      } catch (e) {
43:          if (e instanceof TypeError == false)
44:              throw(e);
45:          throw("helma.Chart needs " + JXLPKGNAME + 
46:                " in lib/ext or application directory " +
47:                "[" + JXLPKGURL + "]");
48:      }
49:  
50:      function getCellStyle(c) {
51:          if (!c)
52:              return;
53:          var result = new Object();
54:          var format = c.getCellFormat();
55:          var font = format.getFont();
56:          if (font.getBoldWeight() > 400)
57:              result.bold = true;
58:          result.italic = font.isItalic();
59:          result.wrap = format.getWrap();
60:          var type = c.getType();
61:          var align = format.getAlignment().getDescription();
62:          if (align == "right" || type == "Number" || type == "Date")
63:              result.align = "right";
64:          else if (align == "centre")
65:              result.align = "center";
66:          return result;
67:      }
68:  
69:      if (sheetName)
70:          var sheet = workbook.getSheet(sheetName);
71:      else
72:          var sheet = workbook.getSheet(0);
73:      if (!sheet)
74:          return;
75:  
76:      prefix = prefix ? prefix + "_" : "chart_";
77:  
78:      this.render = function() {
79:          res.write('<table border="0" cellspacing="1" class="' + 
80:                    prefix + 'table">\n');
81:      
82:          var rowBuf = [];
83:          var rows = sheet.getRows();
84:          var max = 0;
85:          for (var i=0; i<rows; i+=1) {
86:              var row = sheet.getRow(i);
87:              if (row.length > max)
88:                  max = row.length;
89:              rowBuf.push(row);
90:          }
91:      
92:          for (var i in rowBuf) {
93:              res.write('<tr class="' + prefix + 'row">\n');
94:              for (var n=0; n<max; n+=1) {
95:                  if (n < rowBuf[i].length) {
96:                      var c = rowBuf[i][n];
97:                      var str = c.getContents();
98:                      if (str)
99:                          var style = getCellStyle(c);
100:                  }
101:                  res.write('<td class="' + prefix + 'cell"');
102:                  if (style) {
103:                      if (!style.wrap)
104:                          res.write(' nowrap="nowrap"');
105:                      if (style.align)
106:                          res.write(' align="' + style.align + '"');
107:                      res.write(">");
108:                      if (style.bold)
109:                          res.write("<b>");
110:                      if (style.italic)
111:                          res.write("<i>");
112:                  }
113:                  else
114:                      res.write(">");
115:                  res.write(str);
116:                  if (style) {
117:                      if (style.italic)
118:                          res.write("</i>");
119:                      if (style.bold)
120:                          res.write("</b>");
121:                  }
122:                  res.write('</td>\n');
123:              }
124:              res.write('</tr>\n');
125:          }
126:      
127:          res.write('</table>\n');
128:          workbook.close();
129:      };
130:  
131:      this.renderAsString = function() {
132:         res.push();
133:         this.render();
134:         return res.pop();
135:     };
136: 
137:     this.toString = function() {
138:         return "[helma.Chart " + file + "]";
139:     };
140: 
141:     for (var i in this)
142:         this.dontEnum(i);
143: 
144:     return this;
145: }