<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Interview Questions &#187; Upload Excel sheet using jsp/java</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/java-interview-questions/upload-excel-sheet-using-jspjava/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 30 Jul 2010 06:00:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Uploading Excel File  Using Jsp</title>
		<link>http://www.bestjavainterviewquestions.com/uploading-excel-file-using-jsp/</link>
		<comments>http://www.bestjavainterviewquestions.com/uploading-excel-file-using-jsp/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 16:27:39 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Upload Excel sheet using jsp/java]]></category>
		<category><![CDATA[uploading the excelfile]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=541</guid>
		<description><![CDATA[There are two choice for reading and writing the Excel file in your application. 1.By Using the JExcelapi 2.By Jakarta&#8217;s Poi.jar which uses the HSSFSheet read and write. &#8211;&#62; Using the JExcelapi which  is  not suitable for the important data. It fails to read several files and  in most occasions it also fails to create [...]]]></description>
			<content:encoded><![CDATA[<p>There are two choice for reading and writing the Excel file in your application.</p>
<p>1.By Using the JExcelapi</p>
<p>2.By Jakarta&#8217;s Poi.jar which uses the HSSFSheet read and write.</p>
<p>&#8211;&gt; Using the JExcelapi which  is  not suitable for the important data. It fails to read several files and  in most occasions it also fails to create cells. In short JExcelAPI isn&#8217;t suitable for enterprise use.</p>
<p>&#8211;&gt;Where as the POI.jar is a Jakarta  Project&#8217;s which was developed  by pure Java implementation of the Excel file format. It is a mature product and was able to correctly and effortlessly read excel data generated from various sources, including non-MS Excel products like Open Office, and for various versions of Excel. so for this reasons it is Highly recommended.</p>
<p>Before Using this Code you have to download the <strong><em>poi.jar</em></strong> file  and place it in the <em>lib</em> folder of your application (or) place in the jar folder and give the path in the <em>environment variables in the My Computers</em>, and then import the <em>HSSF</em> files and then follow the code</p>
<p><em>&lt;%@ page import = &#8220;java.io.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;java.sql.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;javax.servlet.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;javax.servlet.http.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;java.util.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;java.awt.*&#8221; %&gt;<br />
&lt;%@ page import = &#8220;java.io.File&#8221; %&gt;<br />
&lt;%@ page import = &#8220;java.io.IOException&#8221; %&gt;<br />
&lt;%@ page import = &#8220;javax.swing.filechooser.FileSystemView&#8221; %&gt;</p>
<p>&lt;%@ page import=&#8221;org.apache.poi.hssf.usermodel.HSSFSheet&#8221;%&gt;<br />
&lt;%@ page import=&#8221;org.apache.poi.hssf.usermodel.HSSFWorkbook&#8221;%&gt;<br />
&lt;%@ page import=&#8221;org.apache.poi.hssf.usermodel.HSSFRow&#8221;%&gt;<br />
&lt;%@ page import=&#8221;org.apache.poi.hssf.usermodel.HSSFCell&#8221;%&gt;</p>
<p>&lt;%<br />
//Here Datedas is the value of the length which is retrived from the database in my application</em></p>
<p><em><br />
String fname1=&#8221;File&#8221;-&#8221;+Datedas+&#8221;.xls&#8221;; </em></p>
<p><em>//Giving name to the file<br />
</em></p>
<p><em> //creating a file object</em></p>
<p><em> File fname=new File(fname1);</em></p>
<p><em>//Creating an object to the HSSF Class<br />
</em></p>
<p><em> HSSFWorkbook hwb = new HSSFWorkbook();<br />
</em></p>
<p>//Giving the name to the Excel file which will be created by this HSSFsheet</p>
<p><em>HSSFSheet sheet = hwb.createSheet(&#8220;stock sheet&#8221;);<br />
</em></p>
<p><em>//Creating the row for your data</em></p>
<p><em>HSSFRow pw = sheet.createRow((short)2);<br />
</em></p>
<p><em>//Mention the Heading of your Excel sheet<br />
</em></p>
<p><em> pw.createCell((short) 0).setCellValue(&#8220;S.No&#8221;);<br />
pw.createCell((short) 1).setCellValue(&#8220;Heading1&#8243;);<br />
pw.createCell((short) 2).setCellValue(&#8220;</em><em>Heading2</em><em>&#8220;);<br />
pw.createCell((short) 3).setCellValue(&#8220;</em><em>Heading3</em><em>&#8220;);<br />
pw.createCell((short) 4).setCellValue(&#8220;</em><em>Heading4</em><em>&#8220;);<br />
pw.createCell((short) 5).setCellValue(&#8220;</em><em>Heading5</em><em>&#8220;);<br />
pw.createCell((short) 6).setCellValue(&#8220;</em><em>Heading6</em><em>&#8220;);<br />
pw.createCell((short) 7).setCellValue(&#8220;</em><em>Heading7</em><em>&#8220;);<br />
pw.createCell((short) 8).setCellValue(&#8220;</em><em>Heading8</em><em>&#8220;);<br />
pw.createCell((short) 9).setCellValue(&#8220;</em><em>Heading9</em><em>&#8220;);<br />
pw.createCell((short) 10).setCellValue(&#8220;</em><em>Heading10</em><em>&#8220;);<br />
pw.createCell((short) 11).setCellValue(&#8220;</em><em>Heading1</em><em>1&#8243;);</p>
<p>//String stored1=&#8221;",stored2=&#8221;",stored3=&#8221;",stored4=&#8221;",stored5=&#8221;",stored6=&#8221;",stored7=&#8221;",stored9=&#8221;";<br />
//float stored8=0.0f,stored10=0.0f,stored12=0.0f;<br />
int comprk=1;</p>
<p>int index=3;<br />
//int compno=0;<br />
int sno=0;<br />
while(rs.next())<br />
{</p>
<p>compno=1;<br />
sno++;</p>
<p>System.out.println(&#8220;Testing in the loop  &#8220;+compno);<br />
</em></p>
<p><em>//Creating the Excel Sheet Rows </em></p>
<p><em>HSSFRow row = sheet.createRow((short)index);</em></p>
<p><em> row.createCell((short) 0).setCellValue(sno);</em></p>
<p><em>row.createCell((short)                                                    .setCellValue(Integer.parseInt(rs.getString(1)));<br />
row.createCell((short) 2).setCellValue(rs.getString(2));<br />
row.createCell((short) 3).setCellValue(rs.getString(3));<br />
row.createCell((short) 4).setCellValue(rs.getString(4));<br />
row.createCell((short) 5).setCellValue(rs.getString(5));<br />
row.createCell((short) 6).setCellValue(rs.getString(6));<br />
row.createCell((short) 7).setCellValue(rs.getString(7));<br />
row.createCell((short) 8).setCellValue(rs.getFloat(8));<br />
row.createCell((short) 9).setCellValue(rs.getString(9));<br />
row.createCell((short) 10).setCellValue(rs.getFloat(10));<br />
row.createCell((short) 11).setCellValue(rs.getFloat(13));<br />
index++;<br />
}</p>
<p>FileOutputStream fileOut = new FileOutputStream(fname);</p>
<p>hwb.write(fileOut);<br />
fileOut.flush();<br />
fileOut.close();<br />
out.println(&#8220;&lt;b&gt;Your excel file has been Successfully generated&lt;/b&gt;&#8221;);</p>
<p>%&gt;</em></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/define-precompile-of-jsp-page/" title="Define Precompile of Jsp page"><img src="Array" alt="Define Precompile of Jsp page" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/servlets-and-jsps/" title="Servlets and Jsp&#8217;s"><img src="Array" alt="Servlets and Jsp&#8217;s" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/jsp-interview-questions/" title="JSP Interview Questions"><img src="Array" alt="JSP Interview Questions" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/life-cycle-of-stateless-session-bean/" title="Life Cycle of stateless session bean"><img src="Array" alt="Life Cycle of stateless session bean" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/difference-between-sessionupdate-and-sessionlock/" title="Difference between session.update() and session.lock()"><img src="Array" alt="Difference between session.update() and session.lock()" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/uploading-excel-file-using-jsp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
