මේකයි කතන්දරේ ......
මට ඕනේ JTabel එකක තියෙන Data Excel Sheet එකකට Insert/Write කරගන්න ඕනේ.
මන් Code එකක් try කළා එත් එක වැඩකරන්නේ නැහැ ..පුළුවන් කෙනෙක් ඉන්නවනම් මට මේක කරන හැටි කියල දෙන්න (Source Code).
මේ තියෙන්නේ මගේ Code එක.
String Domestic_Report(String System_Date){
HSSFWorkbook wb;
DefaultTableModel model = (DefaultTableModel) Table_Report.getModel();
// Check if Workbook is present - otherwise create it --------------------------
try {
InputStream inp = new FileInputStream("D:\\Test.xls");
wb = new HSSFWorkbook(inp);
}catch(Exception e) {
wb = new HSSFWorkbook();
}
// Now write to it -------------------------------------------------------------
try {
// Check if we have our sheet
if (wb.getNumberOfSheets()==0) {
wb.createSheet("Domestic P.O.D Report");
}
HSSFSheet sheet = wb.getSheetAt(0);
//-------------------------- Header --------------------------------------------
HSSFRow row = sheet.getRow(1); //Row
if (row==null) {
row = sheet.createRow(1); // Row
}
HSSFCell cell = row.getCell((short)0); // Column
if (cell == null) {
cell = row.createCell((short)0); // Column
}
cell.setCellValue("DATE : "+System_Date);
//------------------------------------------------------------------------------
//--------------------------- Details Report -----------------------------------
for(int r = 6;r<=model.getRowCount();r++){
for(int c=0;c<=model.getColumnCount();c++){
HSSFRow Row = sheet.getRow(r); //Row
if (Row==null) {
Row = sheet.createRow(r); // Row
}
HSSFCell Cell = Row.getCell((short)c); // Column
if (Cell == null) {
Cell = Row.createCell((short)c); // Column
}
cell.setCellValue(model.getValueAt(r, c).toString());
}
}
//------------------------------------------------------------------------------
try (FileOutputStream fileOut = new FileOutputStream("D:\\Test.xls")) {
wb.write(fileOut);
}
}catch (Exception e) {
}
return null;
}
මට ඕනේ JTabel එකක තියෙන Data Excel Sheet එකකට Insert/Write කරගන්න ඕනේ.
මන් Code එකක් try කළා එත් එක වැඩකරන්නේ නැහැ ..පුළුවන් කෙනෙක් ඉන්නවනම් මට මේක කරන හැටි කියල දෙන්න (Source Code).
මේ තියෙන්නේ මගේ Code එක.
String Domestic_Report(String System_Date){
HSSFWorkbook wb;
DefaultTableModel model = (DefaultTableModel) Table_Report.getModel();
// Check if Workbook is present - otherwise create it --------------------------
try {
InputStream inp = new FileInputStream("D:\\Test.xls");
wb = new HSSFWorkbook(inp);
}catch(Exception e) {
wb = new HSSFWorkbook();
}
// Now write to it -------------------------------------------------------------
try {
// Check if we have our sheet
if (wb.getNumberOfSheets()==0) {
wb.createSheet("Domestic P.O.D Report");
}
HSSFSheet sheet = wb.getSheetAt(0);
//-------------------------- Header --------------------------------------------
HSSFRow row = sheet.getRow(1); //Row
if (row==null) {
row = sheet.createRow(1); // Row
}
HSSFCell cell = row.getCell((short)0); // Column
if (cell == null) {
cell = row.createCell((short)0); // Column
}
cell.setCellValue("DATE : "+System_Date);
//------------------------------------------------------------------------------
//--------------------------- Details Report -----------------------------------
for(int r = 6;r<=model.getRowCount();r++){
for(int c=0;c<=model.getColumnCount();c++){
HSSFRow Row = sheet.getRow(r); //Row
if (Row==null) {
Row = sheet.createRow(r); // Row
}
HSSFCell Cell = Row.getCell((short)c); // Column
if (Cell == null) {
Cell = Row.createCell((short)c); // Column
}
cell.setCellValue(model.getValueAt(r, c).toString());
}
}
//------------------------------------------------------------------------------
try (FileOutputStream fileOut = new FileOutputStream("D:\\Test.xls")) {
wb.write(fileOut);
}
}catch (Exception e) {
}
return null;
}
