473,670 Members | 2,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Code for Storing Data directly in Excel File

144 New Member
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 2037

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

Similar topics

2
4333
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
2362
by: Yoavo | last post by:
Hi, I need to read data from excel file. How do I do it ? Yoav.
1
5978
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 data from the excel file to populate it into the dataset. I think i have to use the class Range. Can any one explain how to do it ????????????? Thank YOU
1
6505
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
1365
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
1860
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
1206
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 Initials, Address and contact no...can anyone give me the code
1
4493
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 for my own requirements it does not work. Please help me with an example to import data in colums in exel file into mysql table columns. Thank PHP Lover
0
2109
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 should start from column B in excel. The column A of the excel file should have heading "Extract Policy" followed by checkboxes so that the user can check which policy to extract after downloading the excel file. Can anyone suggest me how to do...
3
2146
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 I might miss? Thanks
0
8468
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4209
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.