use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class SViewer method jbInit.
/**Component initialization*/
private void jbInit() throws Exception {
InputStream i = null;
boolean isurl = false;
if (filename == null)
filename = getParameter("filename");
if (filename == null || filename.substring(0, 7).equals("http://")) {
isurl = true;
if (filename == null)
filename = getParameter("url");
i = getXLSFromURL(filename);
}
HSSFWorkbook wb = null;
if (isurl) {
wb = constructWorkbook(i);
} else {
wb = constructWorkbook(filename);
}
panel = new SViewerPanel(wb, false);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.CENTER);
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class MergedCells method main.
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow(1);
HSSFCell cell = row.createCell(1);
cell.setCellValue("This is a test of merging");
sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class SViewer method constructWorkbook.
private HSSFWorkbook constructWorkbook(String filename) throws FileNotFoundException, IOException {
HSSFWorkbook wb = null;
FileInputStream in = new FileInputStream(filename);
wb = new HSSFWorkbook(in);
in.close();
return wb;
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class SViewer method constructWorkbook.
private HSSFWorkbook constructWorkbook(InputStream in) throws IOException {
HSSFWorkbook wb = null;
wb = new HSSFWorkbook(in);
in.close();
return wb;
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class ReSave method main.
public static void main(String[] args) throws Exception {
boolean initDrawing = false;
boolean saveToMemory = false;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
for (String filename : args) {
if (filename.equals("-dg")) {
initDrawing = true;
} else if (filename.equals("-bos")) {
saveToMemory = true;
} else {
System.out.print("reading " + filename + "...");
FileInputStream is = new FileInputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook(is);
try {
System.out.println("done");
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
HSSFSheet sheet = wb.getSheetAt(i);
if (initDrawing) {
/*HSSFPatriarch dg =*/
sheet.getDrawingPatriarch();
}
}
OutputStream os;
if (saveToMemory) {
bos.reset();
os = bos;
} else {
String outputFile = filename.replace(".xls", "-saved.xls");
System.out.print("saving to " + outputFile + "...");
os = new FileOutputStream(outputFile);
}
try {
wb.write(os);
} finally {
os.close();
}
System.out.println("done");
} finally {
wb.close();
is.close();
}
}
}
}
Aggregations