Search in sources :

Example 71 with POIFSFileSystem

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>");
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) BeanFactory(org.akaza.openclinica.control.managestudy.BeanFactory) ServletContext(javax.servlet.ServletContext) SpreadsheetPreviewNw(org.akaza.openclinica.control.admin.SpreadsheetPreviewNw) File(java.io.File) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 72 with POIFSFileSystem

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();
    }
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) FileOutputStream(java.io.FileOutputStream) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) FileInputStream(java.io.FileInputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 73 with POIFSFileSystem

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.");
}
Also used : HSSFEventFactory(org.apache.poi.hssf.eventusermodel.HSSFEventFactory) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HSSFRequest(org.apache.poi.hssf.eventusermodel.HSSFRequest) FileInputStream(java.io.FileInputStream)

Example 74 with POIFSFileSystem

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);
}
Also used : TrailerStream(org.apache.poi.hdgf.streams.TrailerStream) HDGFDiagram(org.apache.poi.hdgf.HDGFDiagram) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) FileInputStream(java.io.FileInputStream) Stream(org.apache.poi.hdgf.streams.Stream) TrailerStream(org.apache.poi.hdgf.streams.TrailerStream) InputStream(java.io.InputStream)

Example 75 with POIFSFileSystem

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());
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) Test(org.junit.Test)

Aggregations

POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)121 Test (org.junit.Test)58 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)38 InputStream (java.io.InputStream)36 ByteArrayInputStream (java.io.ByteArrayInputStream)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)33 FileInputStream (java.io.FileInputStream)31 File (java.io.File)25 OPOIFSFileSystem (org.apache.poi.poifs.filesystem.OPOIFSFileSystem)15 FileOutputStream (java.io.FileOutputStream)14 OutputStream (java.io.OutputStream)14 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)13 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)13 TempFile (org.apache.poi.util.TempFile)13 IOException (java.io.IOException)12 MutablePropertySet (org.apache.poi.hpsf.MutablePropertySet)7 MutableSection (org.apache.poi.hpsf.MutableSection)7 HashMap (java.util.HashMap)6 DocumentEntry (org.apache.poi.poifs.filesystem.DocumentEntry)6 NDocumentOutputStream (org.apache.poi.poifs.filesystem.NDocumentOutputStream)6