res = classloader.getResource("org/apache/poi/hslf/usermodel/HSLFSlideShow.class");
path = res.getPath();
System.out.println("POI Scratchpad came from " + path);]]></source>
</answer>
</faq>
<faqid="faq-N10019">
<question>
My code uses the scratchpad, compiles fine but fails to run with a "MethodNotFoundException"
</question>
<answer>
<p>You almost certainly have an older version earlier on your
classpath. See the prior answer.</p>
</answer>
</faq>
<faqid="faq-N10025">
<question>
I'm using the poi-ooxml-lite (previously known as poi-ooxml-schemas) jar, but my code is failing with "java.lang.NoClassDefFoundError: org/openxmlformats/schemas/*something*"
</question>
<answer>
<p>To use the new OOXML file formats, POI requires a jar containing
the file format XSDs, as compiled by
<ahref="https://xmlbeans.apache.org/">XMLBeans</a>. These
XSDs, once compiled into Java classes, live in the
I'm trying to stream an XLS file from a servlet and I'm having some trouble. What's the problem?
</question>
<answer>
<p>
The problem usually manifests itself as the junk characters being shown on
screen. The problem persists even though you have set the correct mime type.
</p>
<p>
The short answer is, don't depend on IE to display a binary file type properly if you stream it via a
servlet. Every minor version of IE has different bugs on this issue.
</p>
<p>
The problem in most versions of IE is that it does not use the mime type on
the HTTP response to determine the file type; rather it uses the file extension
on the request. Thus you might want to add a
<strong>.xls</strong> to your request
string. For example
<em>http://yourserver.com/myServelet.xls?param1=xx</em>. This is
easily accomplished through URL mapping in any servlet container. Sometimes
a request like
<em>http://yourserver.com/myServelet?param1=xx&dummy=file.xls</em> is also
known to work.
</p>
<p>
To guarantee opening the file properly in Excel from IE, write out your file to a
temporary file under your web root from your servlet. Then send an http response
to the browser to do a client side redirection to your temp file. (Note that using a
server side redirect using RequestDispatcher will not be effective in this case)
</p>
<p>
Note also that when you request a document that is opened with an
external handler, IE sometimes makes two requests to the webserver. So if your
generating process is heavy, it makes sense to write out to a temporary file, so that multiple
requests happen for a static file.
</p>
<p>
None of this is particular to Excel. The same problem arises when you try to
generate any binary file dynamically to an IE client. For example, if you generate
pdf files using
<ahref="https://xml.apache.org/fop">FOP</a>, you will come across many of the same issues.
</p>
<!-- Thanks to Avik for the answer -->
</answer>
</faq>
<faqid="faq-N10123">
<question>
I want to set a cell format (Data format of a cell) of an excel sheet as ###,###,###.#### or ###,###,###.0000. Is it possible using POI ?
</question>
<answer>
<p>
Yes. You first need to get a DataFormat object from the workbook and call getFormat with the desired format. Some examples are <ahref="../components/spreadsheet/quick-guide.html#DataFormats">here</a>.
</p>
</answer>
</faq>
<faqid="faq-N10133">
<question>
I want to set a cell format (Data format of a cell) of an excel sheet as text. Is it possible using POI ?
</question>
<answer>
<p>
Yes. This is a built-in format for excel that you can get from DataFormat object using the format string "@". Also, the string "text" will alias this format.
</p>
</answer>
</faq>
<faqid="faq-N1013F">
<question>
How do I add a border around a merged cell?
</question>
<answer>
<p>Add blank cells around where the cells normally would have been and set the borders individually for each cell.
We will probably enhance HSSF in the future to make this process easier.</p>
</answer>
</faq>
<faqid="faq-N1014B">
<question>
I am using styles when creating a workbook in POI, but Excel refuses to open the file, complaining about "Too Many Styles".
</question>
<answer>
<p>You just create the styles OUTSIDE of the loop in which you create cells.</p>
automatically compile it for you to generate the source and binary poi-ooxml-full jars.</p>
</answer>
</faq>
<faqid="faq-N101BA">
<question>
An OLE2 ("binary") file is giving me problems, but I can't share it. How can I investigate the problem on my own?
</question>
<answer>
<p>The first thing to try is running the
<ahref="https://blogs.msdn.com/b/officeinteroperability/archive/2011/07/12/microsoft-office-binary-file-format-validator-is-now-available.aspx">Binary File Format Validator</a>
from Microsoft against the file, which will report if the file
complies with the specification. If your input file doesn't, then this
may well explain why POI isn't able to process it correctly. You
should probably in this case speak to whoever is generating the file,
and have them fix it there. If your POI generated file is identified
as having an issue, and you're on the
<ahref="site:howtobuild">latest codebase</a>, report a new
POI bug and include the details of the validation failure.</p>
<p>Another thing to try, especially if the file is valid but POI isn't
behaving as expected, are the POI Dev Tools for the component you're
using. For example, HSSF has <em>org.apache.poi.hssf.dev.BiffViewer</em>
which will allow you to view the file as POI does. This will often
allow you to check that things are being read as you expect, and
narrow in on problem records and structures.</p>
</answer>
</faq>
<faqid="faq-N101D4">
<question>
An OOXML ("xml") file is giving me problems, but I can't share it. How can I investigate the problem on my own?
</question>
<answer>
<p>There's not currently a simple validator tool as there is for the
OLE2 based (binary) file formats, but checking the basics of a file
is generally much easier.</p>
<p>Files such as .xlsx, .docx and .pptx are actually a zip file of XML
files, with a special structure. Your first step in diagnosing the
issues with the input or output file will likely be to unzip the
file, and look at the XML of it. Newer versions of Office will
normally tell you which area of the file is problematic, so
narrow in on there. Looking at the XML, does it look correct?</p>
<p>When reporting bugs, ideally include the whole file, but if you're
unable to then include the snippet of XML for the problem area, and
reference the OOXML standard for what it should contain.</p>
</answer>
</faq>
<faqid="faq-N101E6">
<question>
Why do I get a java.lang.NoClassDefFoundError: javax/xml/stream/XMLEventFactory.newFactory()
</question>
<answer>
<p><strong>Applies to versions <= 3.17 (Java 6): </strong></p>
<p>This error indicates that the class XMLEventFactory does not provide
functionality which POI is depending upon. There can be a number of
different reasons for this:</p>
<ul>
<li>Outdated xml-apis.jar, stax-apis.jar or xercesImpl.jar:<br/>
These libraries were required with Java 5 and lower, but are not actually
required with spec-compliant Java 6 implementations, so try removing those
libraries from your classpath. If this is not possible, try upgrading to a
newer version of those jar files.
</li>
<li>Running IBM Java 6 (potentially as part of WebSphere Application Server):<br/>
IBM Java 6 does not provide all the interfaces required by the XML standards,
only IBM Java 7 seems to provide the correct interfaces, so try upgrading
your JDK.
</li>
<li>Sun/Oracle Java 6 with outdated patchlevel:<br/>
Some of the interfaces were only included/fixed in some of the patchlevels for
Java 6. Try running with the latest available patchlevel or even better use
Java 7/8 where this functionality should be available in all cases.
</li>
</ul>
</answer>
</faq>
<faqid="faq-N10204">
<question>
Can I mix POI jars from different versions?
</question>
<answer>
<p>No. This is not supported.</p>
<p>All POI jars in use must come from the same version. A combination
such as <em>poi-3.11.jar</em> and <em>poi-ooxml-3.9.jar</em> is not
supported, and will fail to work in unpredictable ways.</p>
<p>If you're not sure which POI jars you're using at runtime, and/or
you suspect it might not be the one you intended, see
<ahref="#faq-N10006">this FAQ entry</a> for details on
diagnosing it. If you aren't sure what POI jars you need, see the
<ahref="site:components">Components Overview</a>
for details</p>
</answer>
</faq>
<faqid="faq-N10224">
<question>
Can I access/modify workbooks/documents/slideshows in multiple threads?
What are the multi-threading guarantees that Apache POI makes
</question>
<answer>
<p>In short: <em>Handling different document-objects in different threads will
work. Accessing the same document in multiple threads will not work.</em></p>
<p>This means the workbook/document/slideshow objects are not checked for
thread safety, but any globally held object like global caches or other
data structures are guarded against multi threaded access accordingly.</p>