ASF Bugzilla – Attachment 22937 Details for
Bug 46290
Couldn't create workbook in Solaris 10 sparc - gives Segmentation Fault (core dumped) error
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Java program which is reading a file remotely and trying to create sheet using existing excel template
CreateExcelFile_Copy.java (text/plain), 4.47 KB, created by
Vivek
on 2008-11-25 04:48:10 UTC
(
hide
)
Description:
Java program which is reading a file remotely and trying to create sheet using existing excel template
Filename:
MIME Type:
Creator:
Vivek
Created:
2008-11-25 04:48:10 UTC
Size:
4.47 KB
patch
obsolete
>import com.ssh.sft.*; >import java.util.Iterator; >import java.io.BufferedReader; >import java.io.InputStreamReader; >import java.io.FileWriter; >import java.io.BufferedWriter; >import java.io.BufferedReader; >import org.apache.poi.hssf.usermodel.*; >import java.io.FileInputStream; >import java.net.URL; >import java.net.URI; >import java.io.FileOutputStream; >import org.apache.poi.poifs.filesystem.*; >import java.nio.charset.Charset; >import java.io.FileReader; >import java.io.IOException; > >public class CreateExcelFile_Copy >{ > public static void main(String args[]) throws Exception > { > String fileNames[] = {"criteria_out","ByAnalysisSummary"}; > CreateExcelFile.getCSVs(args[0], args[1]); > CreateExcelFile.createExcelReport(); > } > >public static void createExcelReport(){ > >try{ > String fileNames[] = {"criteria_out","ByAnalysisSummary"}; > FileOutputStream fileOut = new FileOutputStream("ReportTemplate.xls"); > HSSFWorkbook wb1 = null; > wb1 = CreateExcelFile.getReportExcel(fileNames); > System.out.println(" returned 1"); > wb1.write(fileOut); > System.out.println(" returned 2"); > fileOut.close(); > System.out.println(" returned 3"); > wb1 = null; > }catch(Exception ex){ > ex.printStackTrace(); > } >} > >public static void getCSVs(String report, String reportType) throws Exception{ > RegularFile file = null; > > Sft sft = new Sft("*",null); > String inputLine = null; > String FTPUSER = "<USER ID>"; > String FTPHOST = "<AIX Server IP ADDRESS"; > String FTPPATH = "USER HOME PATH"; > > String fullUrl = "sftp://" + FTPUSER +"@" + FTPHOST + FTPPATH + report.trim() + "/"; > > String openURL = null; > > String fileNames[] = {"criteria_out","ByAnalysisSummary"}; > > // Loop to get CSVs to local > > for (int i=0; i<fileNames.length; i++) { > > openURL = fullUrl + fileNames[i] + ".csv"; > System.out.println(" openURL : " + openURL); > URI uri = new URI(openURL); > File f = sft.openFile(uri); > > if (f instanceof RegularFile){ > file = (RegularFile)f; > } > > InputStreamReader inputStreamReader = null; > BufferedReader bufferedReader = null; > FileWriter fstream = null; > BufferedWriter out = null; > > try{ > inputStreamReader = new InputStreamReader(file.openInput()); > bufferedReader = new BufferedReader(inputStreamReader); > > fstream = new FileWriter(fileNames[i] + ".csv"); > out = new BufferedWriter(fstream); > > while ((inputLine = bufferedReader.readLine()) != null) { > out.write(inputLine); > out.newLine(); > } //End of while > out.close(); > bufferedReader.close(); > }catch(IOException ioex){ > System.out.println("IOException 1:"); > ioex.printStackTrace(); > } > System.out.println(" closed streams 1"); > inputStreamReader.close(); > System.out.println(" closed streams 2"); > } //End of for loop >} //End of getCSVs() > > > >public static void getReportExcel(String fileNames[]) throws Exception{ > > String inputLine = null; > System.out.println(" before creating workbook"); > > POIFSFileSystem fs = null; > HSSFWorkbook wb = null; > > try{ > fs = new POIFSFileSystem(new FileInputStream("Template.xls")); > System.out.println(" fs created "); > wb = new HSSFWorkbook(fs); > }catch(Throwable ex){ > ex.getLocalizedMessage(); > System.out.println("Throwable ex:"); > ex.printStackTrace(); > } > System.out.println(" created workboox"); > //Loop to read CSV files locally > > for (int i=0; i<fileNames.length; i++) { > > HSSFSheet sheet = wb.createSheet(fileNames[i]); > int rowNum = 0; > inputLine = null; > > try{ > > FileReader inputFileReader = new FileReader(fileNames[i] + ".csv"); > BufferedReader inputStream = new BufferedReader(inputFileReader); > > while ((inputLine = inputStream.readLine()) != null) { > // Create a row and put some cells in it. Rows are 0 based. > //System.out.println(" inputLine : " + inputLine); > HSSFRow row = sheet.createRow((short)rowNum); > // Create a cell and put a value in it. > //System.out.println(" created row "); > HSSFCell cell = row.createCell((short)0); > //System.out.println(" created cell "); > cell.setEncoding(HSSFCell.ENCODING_COMPRESSED_UNICODE); > //System.out.println(" set encoding "); > cell.setCellValue(inputLine); > //System.out.println(" set values "); > rowNum++; > } > inputStream.close(); > inputFileReader.close(); > }catch(IOException ioe){ > System.out.println("IOException 2:"); > ioe.printStackTrace(); > } > } // End of for loop > System.out.println(" before returning"); > FileOutputStream fileOut = new FileOutputStream("Template.xls"); > wb.write(fileOut); > fileOut.close(); >// return wb; >} // End of getReportExcel() > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 46290
: 22937