473,396 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Java Code for Storing Data directly in Excel File

144 100+
I have a below code which saves 4 html page separately with data and a empty Excel file. This empty Excel file is dependent on this 4 html page data. Only While Opening this Excel file ,Each 4 html page is loading its data into each 4 spreadsheet of this Empty Excel file. Is there any way to modify this code, so that each 4 html page data will be directly load into Excel file in each 4 spreadsheet. Can you please help me? Please let me know if you have any questions? If you know Please modify this below code. I will try in my end.

Expand|Select|Wrap|Line Numbers
  1.  
  2. public void RunReportAndSaveExcelOutput(String reportSearchPath, String saveLocation) 
  3.     {        
  4.  
  5.  
  6.                 Option runOptions[] = new Option[5];
  7.  
  8.     //runOptions = new option[5];
  9.  
  10.         RunOptionBoolean saveOutput = new RunOptionBoolean();
  11.         saveOutput.setName(RunOptionEnum.saveOutput);
  12.         saveOutput.setValue(false);
  13.         runOptions[0] = saveOutput;
  14.  
  15.         RunOptionStringArray outputFormat = new RunOptionStringArray();
  16.         outputFormat.setName(RunOptionEnum.outputFormat);
  17.         outputFormat.setValue(new String[]{"XLS" });
  18.         runOptions[1] = outputFormat;
  19.  
  20.         RunOptionBoolean prompt = new RunOptionBoolean();
  21.         prompt.setName(RunOptionEnum.prompt);
  22.         prompt.setValue(false);
  23.         runOptions[2] = prompt;
  24.  
  25.         RunOptionInt primaryWaitThreshold = new RunOptionInt();
  26.         primaryWaitThreshold.setName(RunOptionEnum.primaryWaitThreshold);
  27.         primaryWaitThreshold.setValue(0);
  28.         runOptions[3] = primaryWaitThreshold;
  29.  
  30.         RunOptionInt secondaryWaitThreshold = new RunOptionInt();
  31.         secondaryWaitThreshold.setName(RunOptionEnum.secondaryWaitThreshold);
  32.         secondaryWaitThreshold.setValue(0);
  33.         runOptions[4] = secondaryWaitThreshold;
  34.  
  35.         SearchPathSingleObject repPath = new SearchPathSingleObject();
  36.         repPath.setValue( reportSearchPath );
  37.  
  38.  
  39. try
  40. {
  41.  
  42. AsynchReply res = getReportService().run(repPath, new ParameterValue[]{}, runOptions);
  43.  
  44.         // If it has not yet completed, keep waiting until it is done.
  45.         int count = 1;
  46.         while(res.getStatus() != AsynchReplyStatusEnum.complete &&
  47.                 res.getStatus() != AsynchReplyStatusEnum.conversationComplete)
  48.         {
  49.             System.out.println("large report - waiting..." + count);
  50.             res = getReportService().wait(res.getPrimaryRequest(), new ParameterValue[]{}, new Option[]{});
  51.             count++;
  52.         }
  53.  
  54.  
  55.         if (res.getStatus().equals(AsynchReplyStatusEnum.complete))
  56.         {
  57.             AsynchDetailReportOutput reportOutput = null;
  58. System.out.println(res.getDetails().length);
  59.  
  60.             for (int i = 0; i < res.getDetails().length; i++)
  61.             {
  62.                 if (res.getDetails()[i] instanceof AsynchDetailReportOutput)
  63.                 {
  64.                     reportOutput = (AsynchDetailReportOutput)res.getDetails()[i];
  65.                     break;
  66.                 }
  67.             }
  68.  
  69.             String excelFile = null;
  70.             String[] data = reportOutput.getOutputPages();
  71.             excelFile = data[0];
  72.             //look for output pages of the excel report.
  73.             BaseClass bcOutput[] = reportOutput.getOutputObjects();
  74.  
  75.  
  76.             if (bcOutput != null && bcOutput.length > 0) 
  77.             {    
  78.                 Output latestOutput = (Output)bcOutput[bcOutput.length - 1];
  79.  
  80.                 PropEnum [] pageProperties = new PropEnum [] {PropEnum.searchPath,PropEnum.defaultName,                                                          PropEnum.data};
  81.                 SearchPathMultipleObject outPage = new SearchPathMultipleObject();
  82.                 outPage.setValue(latestOutput.getSearchPath().getValue() + "//page");
  83.                                 BaseClass[] bcPage = new BaseClass[100000];
  84.  
  85.                 bcPage = cmService.query(outPage, pageProperties, new Sort[]{}, new QueryOptions() );
  86.  
  87.  
  88.                 if (bcPage != null)
  89.                 {    
  90.                     for (int i = 0; i < bcPage.length; i++)
  91.                     {    
  92.                         Page dataPage = (Page)bcPage[i];
  93.                         dataPageName = dataPage.getDefaultName().getValue(); 
  94.                                                 //String dataPageName1 = dataPage.getDefaultName() + "_" + day + "-" + (month + 1) + "-" + year;
  95.                         String saveDataPageFile = saveLocation + "/" + dataPageName ; 
  96.                                                 System.out.println(saveDataPageFile);
  97.                         File file = new File(saveDataPageFile);
  98.                         FileOutputStream fos = new FileOutputStream(file);
  99.                         fos.write(dataPage.getData().getValue());
  100.                         fos.flush();
  101.                         fos.close();
  102.                         //System.out.println("Saving report page - " + saveDataPageFile);
  103.                     }
  104.                 }
  105.  
  106.                 // query to get the report name
  107.                 PropEnum [] reportProperties = new PropEnum [] {PropEnum.defaultName};
  108. Thread.sleep(700);
  109.                 BaseClass [] reportInfo = cmService.query(new SearchPathMultipleObject(reportSearchPath), reportProperties, new Sort[]{}, new QueryOptions());
  110. String saveExcelFile = saveLocation + "/" + reportInfo[0].getDefaultName().getValue() + ".xls"; 
  111.                 File file = new File(saveExcelFile);
  112.                 FileOutputStream fos = new FileOutputStream(file);
  113.                 Base64 b64 = new Base64();    
  114.                 byte[] binaryOutput= null; 
  115. byte[] buffer = new byte[22528];
  116. buffer=excelFile.getBytes();
  117.                 fos.write(buffer); 
  118.                 fos.flush();
  119.                 fos.close();
  120.                 System.out.println("Saving report " + saveExcelFile);
  121.             }
  122.  
  123.             else
  124.                 System.out.println("No output found for report " + reportSearchPath);    
  125.  
  126.  
  127.         }
  128.  
  129.  
  130.  
  131. }
  132. catch(Exception e)
  133.         {
  134. System.out.println(e);    
  135.         }
  136.     }
  137.  
  138.  
Jan 27 '12 #1
0 2029

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: bienwell | last post by:
Hi all, Do you have any source code to import data from Excel file or text file into database in ASP.NET program ? Please give me your reference if you have. Thanks in advance
1
by: Yoavo | last post by:
Hi, I need to read data from excel file. How do I do it ? Yoav.
1
by: madhu sudhan | last post by:
HI, I want to read data from excel file and export this data to dataset. I know abt the basics of opening a file using application, workbook and worksheet classes. But i don't know how to read...
1
by: disha manikumar | last post by:
Simple java code to read an excel sheet and extract only few fields by treating the excel sheet as a flat file. Can anyone suggest a simple java code for this?
1
by: syam217 | last post by:
Please help me out in reading data from Excel file and storing it in SQL Server 2000 database. Its very urgent. Thanks in advance.
3
by: ramona chauhan | last post by:
Hi This is ramona . i want to know the code for reading an excel file. please provide the required code.
1
by: dixon | last post by:
Hi please help i'm trying to read data from excel file using VB 2005 and display it to a listbox and when name clicked on a list box details of that name should be displayed on the labels such as...
1
by: arshigill | last post by:
I want to import data from excel file inot mysql database table but unable to solve this problem. I have searched google and find an example of importing of CSV excel file. But when I modify it...
0
by: JFKJr | last post by:
Hello everyone! I am trying to export Access table data into Excel file in such a way that the table field names should be in the first line of each column in excel file followed by field data, and...
3
by: qfchen | last post by:
Hi In order to save data into excel file in my application, I need to define Dim excelApp As New Excel.Application but I got error message: "Type Excel.Application" is not defined. What component...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.