01: package org.julp.util.common;
02:
03: import java.util.*;
04: import java.io.*;
05: import jxl.*;
06:
07: public class XSL2HTMLUtil {
08:
09: /** Creates a new instance of XSL2HTMLUtil */
10: public XSL2HTMLUtil() {
11: }
12:
13: public String convert(String fileName) {
14: Workbook workbook = null;
15: StringBuffer html = new StringBuffer("<html>\n");
16: try {
17: workbook = Workbook.getWorkbook(new File(fileName));
18: Sheet sheet = workbook.getSheet(0);
19: html.append(" <head><title>");
20: html.append(sheet.getName());
21: html.append(" </title></head>\n");
22: html.append(" <body>\n");
23: html.append(" <table border='1'>\n");
24: int colCount = sheet.getColumns();
25: int rowCount = sheet.getRows();
26: int count = 0;
27: for (int r = 0; r < rowCount; r++) {
28: Cell[] cell = sheet.getRow(r);
29: // if (cell.length < 7){
30: // continue;
31: // }else{
32: // count++;
33: // }
34: html.append(" <tr>\n");
35: html.append(" <td>");
36: html.append(count);
37: html.append("</td>\n");
38: for (int c = 0; c < cell.length; c++) {
39: html.append(" <td>");
40: String value = cell[c].getContents();
41: if (value == null) {
42: value = " ";
43: } else {
44: value = value.replaceAll("\"", "");
45: if (value.trim().equals("")) {
46: value = " ";
47: }
48: }
49: html.append(value);
50: html.append("</td>\n");
51: }
52: html.append(" </tr>\n");
53: }
54: html.append(" </table>\n");
55: html.append(" </body>\n</html>");
56:
57: } catch (IOException ioe) {
58: ioe.printStackTrace();
59: } catch (jxl.read.biff.BiffException be) {
60: be.printStackTrace();
61: } finally {
62: workbook.close();
63: }
64: // System.out.println(html);
65: return html.toString();
66: }
67:
68: }
|