Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
Java Help Please !!!!!
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Hasistranger" data-source="post: 14999125" data-attributes="member: 314292"><p><span style="font-size: 12px"><span style="color: SeaGreen"><strong>මේකයි කතන්දරේ ......</strong></span></span></p><p><span style="font-size: 12px"><span style="color: SeaGreen"><strong>මට ඕනේ JTabel එකක තියෙන Data Excel Sheet එකකට Insert/Write කරගන්න ඕනේ.</strong></span></span></p><p><span style="font-size: 12px"><span style="color: SeaGreen"><strong>මන් Code එකක් try කළා එත් එක වැඩකරන්නේ නැහැ ..පුළුවන් කෙනෙක් ඉන්නවනම් මට මේක කරන හැටි කියල දෙන්න (Source Code).</strong></span></span></p><p><span style="font-size: 12px"><span style="color: SeaGreen"><strong></strong></span></span></p><p><span style="font-size: 12px"><span style="color: SeaGreen"><strong>මේ තියෙන්නේ මගේ Code එක.</strong></span></span></p><p><span style="font-size: 10px"></span></p><p><span style="font-size: 10px"><strong><span style="color: Red">String Domestic_Report(String System_Date){</span></strong></span></p><p><span style="font-size: 10px"></span></p><p> <span style="font-size: 10px"><strong><span style="color: Blue">HSSFWorkbook wb;</span></strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Blue"><span style="font-size: 10px">DefaultTableModel model = (DefaultTableModel) Table_Report.getModel();</span></span></strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Silver">// Check if Workbook is present - otherwise create it --------------------------</span></strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p> <span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>try {</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>InputStream inp = new FileInputStream(<span style="color: SandyBrown">"D:\\Test.xls"</span>);</strong></span></p><p><span style="font-size: 10px"><strong>wb = new HSSFWorkbook(inp);</strong></span></p><p><span style="font-size: 10px"><strong>}catch(Exception e) {</strong></span></p><p><span style="font-size: 10px"><strong>wb = new HSSFWorkbook();</strong></span></p><p><span style="font-size: 10px"><strong>}</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Silver">// Now write to it -------------------------------------------------------------</span></strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>try {</strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Silver">// Check if we have our sheet</span></strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>if (wb.getNumberOfSheets()==0) {</strong></span></p><p><span style="font-size: 10px"><strong>wb.createSheet(<span style="color: SandyBrown">"Domestic P.O.D Report"</span>);</strong></span></p><p><span style="font-size: 10px"><strong>}</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>HSSFSheet sheet = wb.getSheetAt(0);</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Silver"></span></strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Silver">//-------------------------- Header --------------------------------------------</span></strong></span></p><p><span style="font-size: 10px"><strong>HSSFRow row = sheet.getRow(</strong></span><span style="font-size: 10px"><strong><span style="font-size: 10px"><strong>1</strong></span>); <span style="color: Silver">//Row</span></strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>if (row==null) {</strong></span></p><p><span style="font-size: 10px"><strong> row = sheet.createRow(1); <span style="color: Silver">// Row</span></strong></span></p><p><span style="font-size: 10px"><strong> }</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>HSSFCell cell = row.getCell((short)0); <span style="color: Silver">// Column</span></strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>if (cell == null) {</strong></span></p><p><span style="font-size: 10px"><strong> cell = row.createCell((short)0); <span style="color: Silver">// Column</span></strong></span></p><p><span style="font-size: 10px"><strong> }</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>cell.setCellValue(<span style="color: SandyBrown">"DATE : "</span>+System_Date);</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Silver">//------------------------------------------------------------------------------</span></strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Silver"></span></strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Silver">//--------------------------- Details Report -----------------------------------</span></strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>for(int r = 6;r<=model.getRowCount();r++){</strong></span></p><p><span style="font-size: 10px"><strong> </strong></span></p><p><span style="font-size: 10px"><strong>for(int c=0;c<=model.getColumnCount();c++){</strong></span></p><p><span style="font-size: 10px"><strong> </strong></span></p><p><span style="font-size: 10px"><strong>HSSFRow Row = sheet.getRow(r);<span style="color: Silver"> //Row</span></strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>if (Row==null) {</strong></span></p><p><span style="font-size: 10px"><strong> Row = sheet.createRow(r); <span style="color: Silver">// Row</span></strong></span></p><p><span style="font-size: 10px"><strong> }</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>HSSFCell Cell = Row.getCell((short)c); <span style="color: Silver">// Column</span></strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>if (Cell == null) {</strong></span></p><p><span style="font-size: 10px"><strong> Cell = Row.createCell((short)c);<span style="color: Silver"> // Column</span></strong></span></p><p><span style="font-size: 10px"><strong> }</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>cell.setCellValue(model.getValueAt(r, c).toString());</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>}</strong></span></p><p><span style="font-size: 10px"><strong>}</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Silver">//------------------------------------------------------------------------------</span></strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p> <span style="font-size: 10px"><strong>try (FileOutputStream fileOut = new FileOutputStream(<span style="color: SandyBrown">"D:\\Test.xls"</span>)) {</strong></span></p><p><span style="font-size: 10px"><strong> wb.write(fileOut);</strong></span></p><p><span style="font-size: 10px"><strong> }</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong>}catch (Exception e) {</strong></span></p><p><span style="font-size: 10px"><strong>}</strong></span></p><p><span style="font-size: 10px"><strong> </strong></span></p><p><span style="font-size: 10px"><strong>return null;</strong></span></p><p><span style="font-size: 10px"><strong></strong></span></p><p><span style="font-size: 10px"><strong><span style="color: Red">}</span></strong></span></p></blockquote><p></p>
[QUOTE="Hasistranger, post: 14999125, member: 314292"] [SIZE=3][COLOR=SeaGreen][B]මේකයි කතන්දරේ ...... මට ඕනේ JTabel එකක තියෙන Data Excel Sheet එකකට Insert/Write කරගන්න ඕනේ. මන් Code එකක් try කළා එත් එක වැඩකරන්නේ නැහැ ..පුළුවන් කෙනෙක් ඉන්නවනම් මට මේක කරන හැටි කියල දෙන්න (Source Code). මේ තියෙන්නේ මගේ Code එක.[/B][/COLOR][/SIZE] [SIZE=2] [B][COLOR=Red]String Domestic_Report(String System_Date){[/COLOR][/B] [B][COLOR=Blue]HSSFWorkbook wb; [SIZE=2]DefaultTableModel model = (DefaultTableModel) Table_Report.getModel();[/SIZE][/COLOR] [COLOR=Silver]// Check if Workbook is present - otherwise create it --------------------------[/COLOR] try { InputStream inp = new FileInputStream([COLOR=SandyBrown]"D:\\Test.xls"[/COLOR]); wb = new HSSFWorkbook(inp); }catch(Exception e) { wb = new HSSFWorkbook(); } [COLOR=Silver]// Now write to it -------------------------------------------------------------[/COLOR] try { [COLOR=Silver]// Check if we have our sheet[/COLOR] if (wb.getNumberOfSheets()==0) { wb.createSheet([COLOR=SandyBrown]"Domestic P.O.D Report"[/COLOR]); } HSSFSheet sheet = wb.getSheetAt(0); [COLOR=Silver] //-------------------------- Header --------------------------------------------[/COLOR] HSSFRow row = sheet.getRow([/B][/SIZE][SIZE=2][B][SIZE=2][B]1[/B][/SIZE]); [COLOR=Silver]//Row[/COLOR] if (row==null) { row = sheet.createRow(1); [COLOR=Silver]// Row[/COLOR] } HSSFCell cell = row.getCell((short)0); [COLOR=Silver]// Column[/COLOR] if (cell == null) { cell = row.createCell((short)0); [COLOR=Silver]// Column[/COLOR] } cell.setCellValue([COLOR=SandyBrown]"DATE : "[/COLOR]+System_Date); [COLOR=Silver]//------------------------------------------------------------------------------ //--------------------------- Details Report -----------------------------------[/COLOR] for(int r = 6;r<=model.getRowCount();r++){ for(int c=0;c<=model.getColumnCount();c++){ HSSFRow Row = sheet.getRow(r);[COLOR=Silver] //Row[/COLOR] if (Row==null) { Row = sheet.createRow(r); [COLOR=Silver]// Row[/COLOR] } HSSFCell Cell = Row.getCell((short)c); [COLOR=Silver]// Column[/COLOR] if (Cell == null) { Cell = Row.createCell((short)c);[COLOR=Silver] // Column[/COLOR] } cell.setCellValue(model.getValueAt(r, c).toString()); } } [COLOR=Silver]//------------------------------------------------------------------------------[/COLOR] try (FileOutputStream fileOut = new FileOutputStream([COLOR=SandyBrown]"D:\\Test.xls"[/COLOR])) { wb.write(fileOut); } }catch (Exception e) { } return null; [COLOR=Red]}[/COLOR][/B][/SIZE] [/QUOTE]
Insert quotes…
Verification
Hata thunen beduwama keeyada? (60 bedeema thuna)
Post reply
Top
Bottom