You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by elmodai <el...@gmail.com> on 2012/07/27 09:52:39 UTC
Trying to read/extract content from xlsx/xls file and store it on
byte array
Hi,
I'd like to:
1. Read a file excel file from filesystem (disk) and store the data in
memory using byte array.
2. then, write that content to another excel file that must be commited on a
SVN.
I have tried it using pure Java, without libraries like POI. But I couldn't
do it.
I have sucess doing it only with PDF and TXT files, because when I try with
excel file, that fle was created damaged.
Somebody can help me? I only need the explanation to extract the the content
of excel files to byte array.
thank you!
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Trying to read/extract content from xlsx/xls file and store it
on byte array
Posted by elmodai <el...@gmail.com>.
Ok Boss Evgeniy Berlog. I see you are experient programmer. I'm newbie.
Are you developer of POI?
//Ayod El Modai
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544p5710552.html
Sent from the POI - User mailing list archive at Nabble.com.
Re: Trying to read/extract content from xlsx/xls file and store it on
byte array
Posted by Evgeniy Berlog <su...@gmail.com>.
Hi, You are welcome.
Your code will slow down your program.
When you use XSSFWorkbook() constructor POI do a lot of operations which
are not needed for getting byte array(file parsing e.g.).
Regrads, Evgeniy Berlog
On Fri, Jul 27, 2012 at 12:25 PM, elmodai <el...@gmail.com> wrote:
> Hi, thank you!
>
> your tip works fine. But I have a solution good to, look:
>
> FileInputStream ips = new FileInputStream(filePath);
> XSSFWorkbook workb = new XSSFWorkbook(ips);
> ByteArrayOutputStream bos = new ByteArrayOutputStream();
> workb.write(bos);
> bos.close();
> byte[] store = bos.toByteArray();
>
> I think is less complicated with POI.
>
> Thank you again teacher!
>
> On 7/27/12, Evgeniy Berlog [via Apache POI]
> <ml...@n5.nabble.com> wrote:
> >
> >
> > Hi,
> > It is not neccessary use POI to get content of Excel file.
> >
> > you can use such chunk of code:
> >
> > InputStream is = ...
> > ByteArrayOutputStream buffer = new ByteArrayOutputStream();
> >
> > int nRead;
> > byte[] data = new byte[16384];
> >
> > while ((nRead = is.read(data, 0, data.length)) != -1) {
> > buffer.write(data, 0, nRead);
> > }
> >
> > buffer.flush();
> >
> > return buffer.toByteArray();
> >
> > Regrads, Evgeniy Berlog
> >
> > On Fri, Jul 27, 2012 at 10:52 AM, elmodai <el...@gmail.com> wrote:
> >
> >> Hi,
> >>
> >> I'd like to:
> >>
> >> 1. Read a file excel file from filesystem (disk) and store the data in
> >> memory using byte array.
> >> 2. then, write that content to another excel file that must be commited
> >> on
> >> a
> >> SVN.
> >>
> >> I have tried it using pure Java, without libraries like POI. But I
> >> couldn't
> >> do it.
> >> I have sucess doing it only with PDF and TXT files, because when I try
> >> with
> >> excel file, that fle was created damaged.
> >>
> >> Somebody can help me? I only need the explanation to extract the the
> >> content
> >> of excel files to byte array.
> >>
> >> thank you!
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544.html
> >> Sent from the POI - User mailing list archive at Nabble.com.
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> >> For additional commands, e-mail: user-help@poi.apache.org
> >>
> >>
> >
> >
> >
> >
> > _______________________________________________
> > If you reply to this email, your message will be added to the discussion
> > below:
> >
> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544p5710546.html
> >
> > To unsubscribe from Trying to read/extract content from xlsx/xls file and
> > store it on byte array, visit
> >
> http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5710544&code=ZWxtb2RhaUBnbWFpbC5jb218NTcxMDU0NHwyMTM1MjQ5NDQ4
>
>
>
>
> --
> View this message in context:
> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544p5710547.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
Re: Trying to read/extract content from xlsx/xls file and store it
on byte array
Posted by elmodai <el...@gmail.com>.
Hi, thank you!
your tip works fine. But I have a solution good to, look:
FileInputStream ips = new FileInputStream(filePath);
XSSFWorkbook workb = new XSSFWorkbook(ips);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workb.write(bos);
bos.close();
byte[] store = bos.toByteArray();
I think is less complicated with POI.
Thank you again teacher!
On 7/27/12, Evgeniy Berlog [via Apache POI]
<ml...@n5.nabble.com> wrote:
>
>
> Hi,
> It is not neccessary use POI to get content of Excel file.
>
> you can use such chunk of code:
>
> InputStream is = ...
> ByteArrayOutputStream buffer = new ByteArrayOutputStream();
>
> int nRead;
> byte[] data = new byte[16384];
>
> while ((nRead = is.read(data, 0, data.length)) != -1) {
> buffer.write(data, 0, nRead);
> }
>
> buffer.flush();
>
> return buffer.toByteArray();
>
> Regrads, Evgeniy Berlog
>
> On Fri, Jul 27, 2012 at 10:52 AM, elmodai <el...@gmail.com> wrote:
>
>> Hi,
>>
>> I'd like to:
>>
>> 1. Read a file excel file from filesystem (disk) and store the data in
>> memory using byte array.
>> 2. then, write that content to another excel file that must be commited
>> on
>> a
>> SVN.
>>
>> I have tried it using pure Java, without libraries like POI. But I
>> couldn't
>> do it.
>> I have sucess doing it only with PDF and TXT files, because when I try
>> with
>> excel file, that fle was created damaged.
>>
>> Somebody can help me? I only need the explanation to extract the the
>> content
>> of excel files to byte array.
>>
>> thank you!
>>
>>
>>
>> --
>> View this message in context:
>> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544.html
>> Sent from the POI - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544p5710546.html
>
> To unsubscribe from Trying to read/extract content from xlsx/xls file and
> store it on byte array, visit
> http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5710544&code=ZWxtb2RhaUBnbWFpbC5jb218NTcxMDU0NHwyMTM1MjQ5NDQ4
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544p5710547.html
Sent from the POI - User mailing list archive at Nabble.com.
Re: Trying to read/extract content from xlsx/xls file and store it on
byte array
Posted by Evgeniy Berlog <su...@gmail.com>.
Hi,
Fist of all, please make sure that you use last version of POI, you can get
it from this link
https://builds.apache.org/job/POI/lastSuccessfulBuild/artifact/build/dist/
If you still have this problem, please show the content of the method
insertTitle(...),
so I will try to reproduce and fix the problem.
Regards, Evgeniy
On Thu, Oct 25, 2012 at 11:36 AM, elmodai <el...@gmail.com> wrote:
> Hi Evgeniy!
>
> I experiencing dififulties to fit text on columns using
> autoSizeColumn(int), even using setColumnWidth(short, short). It doesn work
>
> look at the code below:
>
> insertTitle(wb, row0, j++, "Codigo de infraccao");
> sheet.autoSizeColumn(9);
> insertTitle(wb, row0, j++, "Comentarios");
> sheet.autoSizeColumn(10);
>
> When I generate the excel. I havte to drag the column indexed with 9 to see
> the text "Codigo de infraccao".
>
> Can you help me?
>
> On Fri, Jul 27, 2012 at 10:49 AM, Evgeniy Berlog [via Apache POI] <
> ml-node+s1045710n5710546h37@n5.nabble.com> wrote:
>
> > Hi,
> > It is not neccessary use POI to get content of Excel file.
> >
> > you can use such chunk of code:
> >
> > InputStream is = ...
> > ByteArrayOutputStream buffer = new ByteArrayOutputStream();
> >
> > int nRead;
> > byte[] data = new byte[16384];
> >
> > while ((nRead = is.read(data, 0, data.length)) != -1) {
> > buffer.write(data, 0, nRead);
> > }
> >
> > buffer.flush();
> >
> > return buffer.toByteArray();
> >
> > Regrads, Evgeniy Berlog
> >
> > On Fri, Jul 27, 2012 at 10:52 AM, elmodai <[hidden email]<
> http://user/SendEmail.jtp?type=node&node=5710546&i=0>>
> > wrote:
> >
> > > Hi,
> > >
> > > I'd like to:
> > >
> > > 1. Read a file excel file from filesystem (disk) and store the data in
> > > memory using byte array.
> > > 2. then, write that content to another excel file that must be commited
> > on
> > > a
> > > SVN.
> > >
> > > I have tried it using pure Java, without libraries like POI. But I
> > couldn't
> > > do it.
> > > I have sucess doing it only with PDF and TXT files, because when I try
> > with
> > > excel file, that fle was created damaged.
> > >
> > > Somebody can help me? I only need the explanation to extract the the
> > > content
> > > of excel files to byte array.
> > >
> > > thank you!
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544.html
> > > Sent from the POI - User mailing list archive at Nabble.com.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]<
> http://user/SendEmail.jtp?type=node&node=5710546&i=1>
> > > For additional commands, e-mail: [hidden email]<
> http://user/SendEmail.jtp?type=node&node=5710546&i=2>
> > >
> > >
> >
> >
> > ------------------------------
> > If you reply to this email, your message will be added to the discussion
> > below:
> >
> >
> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544p5710546.html
> > To unsubscribe from Trying to read/extract content from xlsx/xls file
> and
> > store it on byte array, click here<
> http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5710544&code=ZWxtb2RhaUBnbWFpbC5jb218NTcxMDU0NHwyMTM1MjQ5NDQ4
> >
> > .
> > NAML<
> http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
> >
> >
>
>
>
>
> --
> View this message in context:
> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544p5711289.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
Re: Trying to read/extract content from xlsx/xls file and store it
on byte array
Posted by elmodai <el...@gmail.com>.
Hi Evgeniy!
I experiencing dififulties to fit text on columns using
autoSizeColumn(int), even using setColumnWidth(short, short). It doesn work
look at the code below:
insertTitle(wb, row0, j++, "Codigo de infraccao");
sheet.autoSizeColumn(9);
insertTitle(wb, row0, j++, "Comentarios");
sheet.autoSizeColumn(10);
When I generate the excel. I havte to drag the column indexed with 9 to see
the text "Codigo de infraccao".
Can you help me?
On Fri, Jul 27, 2012 at 10:49 AM, Evgeniy Berlog [via Apache POI] <
ml-node+s1045710n5710546h37@n5.nabble.com> wrote:
> Hi,
> It is not neccessary use POI to get content of Excel file.
>
> you can use such chunk of code:
>
> InputStream is = ...
> ByteArrayOutputStream buffer = new ByteArrayOutputStream();
>
> int nRead;
> byte[] data = new byte[16384];
>
> while ((nRead = is.read(data, 0, data.length)) != -1) {
> buffer.write(data, 0, nRead);
> }
>
> buffer.flush();
>
> return buffer.toByteArray();
>
> Regrads, Evgeniy Berlog
>
> On Fri, Jul 27, 2012 at 10:52 AM, elmodai <[hidden email]<http://user/SendEmail.jtp?type=node&node=5710546&i=0>>
> wrote:
>
> > Hi,
> >
> > I'd like to:
> >
> > 1. Read a file excel file from filesystem (disk) and store the data in
> > memory using byte array.
> > 2. then, write that content to another excel file that must be commited
> on
> > a
> > SVN.
> >
> > I have tried it using pure Java, without libraries like POI. But I
> couldn't
> > do it.
> > I have sucess doing it only with PDF and TXT files, because when I try
> with
> > excel file, that fle was created damaged.
> >
> > Somebody can help me? I only need the explanation to extract the the
> > content
> > of excel files to byte array.
> >
> > thank you!
> >
> >
> >
> > --
> > View this message in context:
> >
> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544.html
> > Sent from the POI - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5710546&i=1>
> > For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=5710546&i=2>
> >
> >
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544p5710546.html
> To unsubscribe from Trying to read/extract content from xlsx/xls file and
> store it on byte array, click here<http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5710544&code=ZWxtb2RhaUBnbWFpbC5jb218NTcxMDU0NHwyMTM1MjQ5NDQ4>
> .
> NAML<http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544p5711289.html
Sent from the POI - User mailing list archive at Nabble.com.
Re: Trying to read/extract content from xlsx/xls file and store it on
byte array
Posted by Evgeniy Berlog <su...@gmail.com>.
Hi,
It is not neccessary use POI to get content of Excel file.
you can use such chunk of code:
InputStream is = ...
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
return buffer.toByteArray();
Regrads, Evgeniy Berlog
On Fri, Jul 27, 2012 at 10:52 AM, elmodai <el...@gmail.com> wrote:
> Hi,
>
> I'd like to:
>
> 1. Read a file excel file from filesystem (disk) and store the data in
> memory using byte array.
> 2. then, write that content to another excel file that must be commited on
> a
> SVN.
>
> I have tried it using pure Java, without libraries like POI. But I couldn't
> do it.
> I have sucess doing it only with PDF and TXT files, because when I try with
> excel file, that fle was created damaged.
>
> Somebody can help me? I only need the explanation to extract the the
> content
> of excel files to byte array.
>
> thank you!
>
>
>
> --
> View this message in context:
> http://apache-poi.1045710.n5.nabble.com/Trying-to-read-extract-content-from-xlsx-xls-file-and-store-it-on-byte-array-tp5710544.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>