use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project OpenClinica by OpenClinica.
the class FormServlet method doGet.
@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
PrintWriter pw = httpServletResponse.getWriter();
HorizontalFormBuilder builder = new HorizontalFormBuilder();
SpreadsheetPreviewNw spnw = new SpreadsheetPreviewNw();
BeanFactory beanFactory = new BeanFactory();
ServletContext context = this.getServletContext();
String path = context.getRealPath("/");
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(new File(path + "group_demo_nw.xls")));
HSSFWorkbook wb = new HSSFWorkbook(fs);
Map<String, Map> allMap = spnw.createCrfMetaObject(wb);
/*
* Map gmap = spnw.createGroupsMap(wb); Map map2 =
* spnw.createItemsOrSectionMap(wb,"items"); FormGroupBean fgBean =
* beanFactory.createFormGroupBeanFromMap(gmap); DisplayFormGroupBean
* displayGroup = new DisplayFormGroupBean(); List itemsDisplayList =
* beanFactory. createDisplayItemBeansFromMap(map2,"group_demo");
* displayGroup.setFormGroupBean(fgBean);
* displayGroup.setItems(itemsDisplayList);
*/
List<DisplayItemGroupBean> formGroupsL = new ArrayList<DisplayItemGroupBean>();
String crfName = (String) allMap.get("crf_info").get("crf_name");
Map sections = allMap.get("sections");
Map sectionMap = (Map) sections.get(1);
String sectionLabel = (String) sectionMap.get("section_label");
formGroupsL = beanFactory.createGroupBeans(allMap.get("items"), allMap.get("groups"), sectionLabel, crfName);
// formGroupsL.add(displayGroup);
builder.setDisplayItemGroups(formGroupsL);
pw.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + "<head>\n" + "\t<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n" + "\t<title>test form</title><link rel=\"stylesheet\" href=\"includes/styles.css\" type=\"text/css\">\n" + " <link rel=\"stylesheet\" href=\"includes/styles2.css\" type=\"text/css\">\n" + " <script type=\"text/javascript\" language=\"JavaScript\" src=\n" + " \"includes/repetition-model/repetition-model.js\"></script>" + "</head>\n" + "<body>");
pw.write(builder.createMarkup());
pw.write("</body>\n" + "</html>");
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class ReadWriteWorkbook method main.
public static void main(String[] args) throws IOException {
FileInputStream fileIn = null;
FileOutputStream fileOut = null;
try {
fileIn = new FileInputStream("workbook.xls");
POIFSFileSystem fs = new POIFSFileSystem(fileIn);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(2);
if (row == null)
row = sheet.createRow(2);
HSSFCell cell = row.getCell(3);
if (cell == null)
cell = row.createCell(3);
cell.setCellType(CellType.STRING);
cell.setCellValue("a test");
// Write the output to a file
fileOut = new FileOutputStream("workbookout.xls");
wb.write(fileOut);
} finally {
if (fileOut != null)
fileOut.close();
if (fileIn != null)
fileIn.close();
}
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class EventExample method main.
/**
* Read an excel file and spit out what we find.
*
* @param args Expect one argument that is the file to read.
* @throws IOException When there is an error processing the file.
*/
public static void main(String[] args) throws IOException {
// create a new file input stream with the input file specified
// at the command line
FileInputStream fin = new FileInputStream(args[0]);
// create a new org.apache.poi.poifs.filesystem.Filesystem
POIFSFileSystem poifs = new POIFSFileSystem(fin);
// get the Workbook (excel part) stream in a InputStream
InputStream din = poifs.createDocumentInputStream("Workbook");
// construct out HSSFRequest object
HSSFRequest req = new HSSFRequest();
// lazy listen for ALL records with the listener shown above
req.addListenerForAllRecords(new EventExample());
// create our event factory
HSSFEventFactory factory = new HSSFEventFactory();
// process our events based on the document input stream
factory.processEvents(req, din);
// once all the events are processed close our file input stream
fin.close();
// and our document input stream (don't want to leak these!)
din.close();
System.out.println("done.");
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class HDGFFileHandler method handleFile.
@Override
public void handleFile(InputStream stream, String path) throws IOException {
POIFSFileSystem poifs = new POIFSFileSystem(stream);
HDGFDiagram diagram = new HDGFDiagram(poifs);
Stream[] topLevelStreams = diagram.getTopLevelStreams();
assertNotNull(topLevelStreams);
for (Stream str : topLevelStreams) {
assertTrue(str.getPointer().getLength() >= 0);
}
TrailerStream trailerStream = diagram.getTrailerStream();
assertNotNull(trailerStream);
assertTrue(trailerStream.getPointer().getLength() >= 0);
diagram.close();
poifs.close();
// writing is not yet implemented... handlePOIDocument(diagram);
}
use of org.apache.poi.poifs.filesystem.POIFSFileSystem in project poi by apache.
the class TestBugs method bug51461.
/**
* File with exactly 256 data blocks (+header block)
* shouldn't break on POIFS loading
*/
@SuppressWarnings("resource")
@Test
public void bug51461() throws Exception {
byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51461.xls");
HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem(new ByteArrayInputStream(data)).getRoot(), false);
HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem(new ByteArrayInputStream(data)).getRoot(), false);
assertEquals(2, wbPOIFS.getNumberOfSheets());
assertEquals(2, wbNPOIFS.getNumberOfSheets());
}
Aggregations