
br.com.objectos.way.io.SheetXlsApachePOI Maven / Gradle / Ivy
/*
* Copyright 2013 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.way.io;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import br.com.objectos.core.lang.Strings;
/**
* @author [email protected] (Marcio Endo)
*/
class SheetXlsApachePOI extends AbstractSheetXls implements SheetXls {
private final TableWriter delegate;
private final List entities;
private String name;
public SheetXlsApachePOI(TableWriter delegate, List entities) {
this.delegate = delegate;
this.entities = entities;
}
@Override
public SheetXls named(String name) {
this.name = name;
return this;
}
@Override
public byte[] toByteArray() throws IOException {
POIWorkbook wb = new POIWorkbook();
apachePOI(wb);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
wb.write(stream);
return stream.toByteArray();
}
@Override
public void writeTo(File file) throws IOException {
POIWorkbook wb = new POIWorkbook();
apachePOI(wb);
FileOutputStream stream = new FileOutputStream(file);
wb.write(stream);
}
@Override
void apachePOI(POIWorkbook wb) {
POISheet sheet = Strings.isNullOrEmpty(name) ? wb.createSheet() : wb.createSheet(name);
delegate.apachePOI(sheet);
TableHeader header = delegate.getHeader();
header.apachePOI(sheet);
TableBody body = delegate.getBody();
body.apachePOI(sheet, header.maxSize, entities);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy