Excel多工作表导出源码改造 请版主多多帮忙啊
class XlsExport2
{
Workbook b = new Workbook();
public void export(ReportDocument doc)
{
for(PageView v: doc -> generatePages() -> PageView[])
{
sheet = new Sheet();
v -> sheet
b.add(sheet)
}
}
}
x = new XlsExport2();
for(ReportDocument d:docs)
{
x.export(d);
}
x.close();
这个代码是之前贴出的
看了 XlsExport类 给添加了一个方法
/**
* DOCUMENT ME!
*
* @param pp DOCUMENT ME!
* @param pi DOCUMENT ME!
* @param sheetName DOCUMENT ME!
*
* @throws Exception DOCUMENT ME!
*/
public void exports(PageView pp, int pi, String[] sheetNames)
throws Exception {
ArrayList xs = new ArrayList();
ArrayList ys = new ArrayList();
ArrayList labels = new ArrayList();
frozenRow = frozenColumn = -1;
// if (sheetNames == null) {
// sheetName = "Page " + (pi);
// }
splitView(pp, xs, ys, labels);
for (String sheetName : sheetNames) {
if (!(this.onepagemode && (this.sheet != null) && ((this.lastRow + ys.size()) < 60000))) {
sheet = w.createSheet(sheetName, pi);
sheet.getSettings().setShowGridLines(false);
sheet.getSettings().setBottomMargin(0);
sheet.getSettings().setTopMargin(0);
sheet.getSettings().setLeftMargin(0);
sheet.getSettings().setRightMargin(0);
for (int i = 1; i < xs.size(); i++) {
int width = ((Integer) xs.get(i)).intValue() -
((Integer) xs.get(i - 1)).intValue();
CellView cv = new CellView();
cv.setSize(Math.round(scale_x * width));
sheet.setColumnView(i - 1, cv);
}
this.lastRow = 0;
}
for (int i = 1; i < ys.size(); i++) {
int height = ((Integer) ys.get(i)).intValue() - ((Integer) ys.get(i - 1)).intValue();
sheet.addCell(new Blank(0, i - 1 + lastRow));
sheet.setRowView(i - 1 + lastRow, Math.round(scale_y * height));
}
for (int y = 0; y < grid.length; y++) {
int x = 0;
for (x = 0; x < grid[y].length; x++) {
if (grid[y][x].element != null) {
View element = grid[y][x].element;
if (element instanceof TextView) {
try {
exportText(sheet, (TextView) element, grid[y][x], x, y + lastRow);
} catch (WriteException e) {
e.printStackTrace();
}
} else {
exportImage(sheet, (ImageView) element, grid[y][x], x, y + lastRow);
}
x += (grid[y][x].colSpan - 1);
}
}
}
if (frozenRow > -1) {
sheet.getSettings().setHorizontalFreeze(frozenColumn);
sheet.getSettings().setVerticalFreeze(frozenRow);
}
if (onepagemode) {
this.lastRow += (ys.size() - 2);
}
}
}