com.dhtmlx.xml2excel.HTMLWriter Maven / Gradle / Ivy
package com.dhtmlx.xml2excel;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
public class HTMLWriter extends BaseWriter{
int rows = 0;
int cols = 0;
int fontSize = -1;
String watermark = null;
public void generate(String xml, HttpServletResponse resp) throws IOException {
CSVxml data = new CSVxml(xml);
resp.setCharacterEncoding("UTF-8");
resp.setContentType("application/vnd.ms-excel");
resp.setCharacterEncoding("UTF-8");
resp.setHeader("Content-Disposition", "attachment;filename=grid.xls");
resp.setHeader("Cache-Control", "max-age=0");
String[] csv;
int colsnum = 0;
PrintWriter writer = resp.getWriter();
Colors colors = getColors(data);
startHTML(writer, colors);
csv = data.getHeader();
if (csv != null)colsnum = csv.length;
while(csv != null){
writer.append(dataAsString(csv, "header"));
csv = data.getHeader();
}
csv = data.getRow();
if (csv != null){
colsnum = csv.length;
cols = csv.length;
}
while(csv != null){
String className = rows%2 == 0 ? "cell_odd" : "cell_even";
writer.append(dataAsString(csv, className));
csv = data.getRow();
rows +=1;
}
csv = data.getFooter();
if (csv != null)colsnum = csv.length;
while(csv != null){
writer.append(dataAsString(csv, "footer"));
writer.flush();
csv = data.getFooter();
}
drawWatermark(writer, colsnum);
endHTML(writer);
writer.flush();
writer.close();
}
private void drawWatermark(PrintWriter writer, int colsnum) {
if (watermark != null)
writer.append("" + watermark + " ");
}
private void endHTML(PrintWriter writer) {
writer.append("