Problem displaying an Excel File: Please Help

Hello,
I spent 3 hours this morning reading the forum on how to display an Excel file in the browser using JSP and I apologize in advance if the answer is in the forum.
I cut and paste many examples: My goal is to display an excel file on the browser.
Below is the code but the result is a disaster (please se after the code the result).
My question is how can I display an excel file using the browser. What's wrong with my code. Apparently it worked for many people on the forum.
Please help. I must do that by tomorrow and I had spent already so many hours.
THANK YOU SO MUCH IN ADVANCE.
So far the forum had helped me a lot.
<%@ page language="java" import="java.io.*" %>
<%
String myfile = new String("/temp/temp.xls");
File fileName = new File(myfile);
// Setup our streams
FileInputStream fis = null;
ServletOutputStream out1 = response.getOutputStream();
// Set content type and other response header
response.setContentType(getServletContext().getMimeType(fileName.getName()));
//response.setContentType("application/excel-document");
//response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment; filename=\"" + fileName.getName());
response.setContentLength((int) fileName.length());
// Read in the file from the correct place and stream it to the user
int iRead;
FileInputStream stream = null;
try
stream = new FileInputStream(myfile);
while ((iRead = stream.read()) != -1)
out1.write(iRead);
out1.flush();
} catch (IOException i) {}
%>
RESULT:
������>�� �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� ���@����\p Yahel Malkin B�a�=���=��@�7 �������Oh��+'��0p08 P \h� Yahel Malkinn@�|�$�+�@�|�$�+�������.��+,��0�HP X`hp x ��� competitivePricingReportSave Worksheets���� ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Root Entry�������� �F��T�+�����Workbook������������SummaryInformation(����DocumentSummaryInformation8������������

For those who are having the same problem than me here the solution:
In fact I was only interested in saving the file
<%@ page language="java" import="java.io.*" %>
<%
String myfile = new String("/temp/temp.csv");
response.setContentType ("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=\""+myfile+"\"");
int iRead;
// Setup our streams
FileInputStream fis = null;
ServletOutputStream out1 = response.getOutputStream();
FileInputStream stream = null;
try
stream = new FileInputStream(myfile);
while ((iRead = stream.read()) != -1) {
out1.write(iRead);
out1.flush();
} catch (IOException i) {}
%>

Similar Messages

  • Hello My ipads Power button is not working properly when I press it once it shows option to turn off instead of locking and some other display problems like it suddenly lockes down or display disappears ...Please help. Thank You

    Hello My ipads Power button is not working properly when I press it once it shows option to turn off instead of locking and some other display problems like it suddenly lockes down or display disappears ...Please help. Thank You

    Thanks for that information!
    I'm sure I will be calling AppleCare, but the problem is, they charge for the phone calls don't they? Because I don't have money to be spending to be on the phone with a support service.
    In other things, it seemed like the only time my MacBook was working was when I had Snow Leopard without the 10.6.8 update download that was supposed to be done to prepare for OS X Lion.
    When I look at the information of my HD it says that I have 10.6.8 but that was the install that it claimed to have failed and caused me to restart resulting in all of the repeated problems.
    Also, because my computer is currently down, and I've lost all files how would that effect the use of my iPhone? Because if it doesn't get fixed by the time OS 5 is released, how would I be able to upgrade?!

  • I'm getting this problem when trying to update my iphone 3gs it says that the iphone software could not be contacted and I went on youtube got some advise to go into my hard drive to fix the error I have nothing in my host file please help me if you can

    I'm getting this problem when trying to update my iphone 3gs it says that the iphone software could not be contacted and I went on youtube got some advise to go into my hard drive to fix the error I have nothing in my host file please help me if you can this is all new to me.

    Read this: iOS 4: Updating your device to iOS 5 or later
    ... oh I think it is a 3gs or a 3
    This makes a difference. What does it say in Settings > General > About?

  • I'm having a problem saving a pages document as another format, like a Word document or PDF file.  I've never had this problem in the past.  Please help me!  I need to have this fixed a.s.a.p.

    Hello everyone,
    I'm currently having a problem saving a Pages document as another format, such as a Word document or PDF file.  I've never had this problem before with Pages.  Please help me!  I need to have this completed a.s.a.p.
    Thanks,
    Amy

    To save as a PDF, you do that from Print
    To save as Wrod format, you export
    Allan

  • Have problems with Mail on MacBook running OS X Mavericks. It suddenly became stuck: won't quit and won't display any messages. Please help.

    Have problems with Mail on MacBook running OS X Mavericks. It suddenly became stuck: won't quit and won't display any messages. Please help.

    Select Force Quit from under the Apple menu and select Mail (it may say that it isn't responding).
    Clinton

  • How i will display an Excel file in java

    Hi,
    I have an excel File, Now i want to show it from java, i can do it by clicking an button. So when i will click a button then it will display that excel file thatt means it will be open. Is there anybody can help me?
    Please give me a sample. I need thid urgently. Please help me.
    With regards
    Bina

    look in your "jexcelapi_2_5_9" package, in order to print you have to have something that understands the file strucuture of the object you want to print--ie knows what an excel file is.

  • Problem with an excel file

    Dear All,
    I have a problem with an EXCEL file, i'm in a domain with windows server 2003 and all of the computer have windows 7, a user had open 3 weeks ago a fil excel after she gone on holiday so the file remain open (i don't know how) by she.
    I've try with all unlocker program to make the file deletable, but not work... it is very strange because if i try to open it with the account of the user that open the file appears always the same error (open read only)...
    Could you help me?
    thanks

    Hi,
    You may end the Excel process first, the “PsTools” have a pskill command that you can use to end a process remotely.
    Here’s a simple command:
    pskill \\computer –u username -p password  excel.exe
    For more information, please see the KB below:
    http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx
    Best Regards

  • Illustrator CS4 wont save files, please help?

    You can edit a file, go to save, close it down, then when you re-open it the changes made have not been saved?? No error message or warning pops up, and it all looks ok like it has saved properly, until you open it up again. This also happens when you use 'save as' command if you use the original file name. If however you type in a different file name - it saves ok. But obviously that is not great as you cant now trust or rely on the save mechanism of the programme, to make sure any changes to artwork have been stored!! I have never seen an issue like this, it is worrying, I hope somebody can help?
    Thanks.
    We are running CS4 on windows7 - yes PC!!!

    We save in EPS, and its not just one file, its a variety of different files and it seems to be random as to which files it does it on, some work fine - some don't. And it can be anything from a minor text change to a colour change, it doesnt seem to matter on the change made, it reacts the same.
    The files are saved over a network connection to a large external hard drive.
    Its really puzzling and now starting to cause problems as we do a fair bit of work in it, and can't trust one of the most important features, and that any changes that have been done have been saved and stored!
    Hope maybe you can help with any thoughts at all.
    Cheers.
    Date: Thu, 24 Jun 2010 03:41:40 -0600
    From: [email protected]
    To: [email protected]
    Subject: Illustrator CS4 wont save files, please help?
    What file format do you save it in?
    What kinds of changes did you make in that file?
    Where do you save the file (removable or network media)?
    >

  • How to view corrupted word files, please help?

    Can't view doc corrupted file .How to recover unsaved documents WORD? how to view corrupted word files, please help

    It could be Word or even Windows that is having the problem. Before you start trying to restore a backup or repair a file, try opening other documents.
    Try opening your "corrupt" document from another computer. Also you can try to make a copy of corrupted files. (It could work) : http://www.filerepairforum.com/forum/microsoft/microsoft-aa/word/968-i-would-be-grateful-for-any-help-to-repair-or-the-procedures-word-files
    But if nothing helps, you can try to recover it by using DOCX Viewer Tool Download free demo versions of this software from website: http://www.docx.viewertool.com/ It’s
    gonna help.

  • The status bar is pushed up at about 3/4 of the screen, so I can view onlu firefox at about 1/4, good thing there is a scroll bar, but below the status bar is white display? can u please help me, I want to drag down the status bar so I can have a full vi

    The status bar is pushed up at about 3/4 of the screen, so I can view only Firefox at about 1/4, good thing there is a scroll bar, but below the status bar is white display? can u please help me, I want to drag down the status bar so I can have a full view
    == This happened ==
    Every time Firefox opened

    Your code is absolutely unreadable - even if someone was willing to
    help, it's simply impossible. I do give you a few tips, though: If you
    understand your code (i.e. if it really is YOUR code), you should be
    able to realize that your minimum and maximum never get set (thus they
    are both 0) and your exam 3 is set with the wrong value. SEE where
    those should get set and figure out why they're not. Chances are you
    are doing something to them that makes one 'if' fail or you just
    erroneously assign a wrong variable!

  • TS3899 In my iPad 2 with IO6 today I can not send emails from my gmail account, they go to the outbox directly...why? How can i solve this problem? ..I restarted the IPad but the problem was not solved. Please help.

    In my iPad 2 with IO6 today I can not send emails from my gmail account, they go to the outbox directly...why? How can i solve this problem? ..I restarted the IPad but the problem was not solved. Please help.

    Greetings,
    Questions:
    1. What version of the Mac OS are you running (Apple > About this Mac)?
    2. What version of the iOS are you running (Settings > About)?
    3. Do you use MobileMe/ iCloud or another server based sync solution like Google or Yahoo?
    4. Do other changes to synced information like Address Book content sync successfully back and forth?
    Based on your description it sounds like you have a 1 way sync issue.  Events sync fine between the iOS devices and fine from the computer to the iOS devices but not from the iOS devices to the computer.
    Try:
    Backup your computer and iOS devices before doing anything else:
    http://support.apple.com/kb/HT1427
    http://support.apple.com/kb/ht1766
    Ensure all the devices in use are fully up to date: Apple > Software Update / Settings > General > Software Update
    Make separate backups of critical data:
    Backup your computer Addressbook: http://docs.info.apple.com/article.html?path=AddressBook/4.0/en/ad961.html
    Backup your computer iCal: http://support.apple.com/kb/HT2966
    Reset syncing on your Mac: http://support.apple.com/kb/TS1627
    Reply back if that does not resolve your issue.
    Hope that helps.

  • TS1363 My iPod Nano 7th Generation couldn't be detected by iTunes when I plugged in. I tried resolving the issue by uninstalling the iTunes and then install it back again but yet still the same problem exist. Can you please help me to solve this issue?

    My iPod Nano 7th Generation couldn't be detected by iTunes when I plugged in. I tried resolving the issue by uninstalling the iTunes and then install it back again but yet still the same problem exist. Can you please help me to solve this issue? I have already updated to the latest version of iTunes on my Windows 8 and I cannot synchronize my iPod for the time being. Please do help me to solve this problem. Thank You.

    uninstall all iTunes,5 programes,this worked for me after reinstall them

  • Oracle reports to display PDF/Excel files stored in the Database

    can we use Oracle reports to view/display PDF/Excel files stored in the Database? Thanks Lalitha

    A document stored in the database can be easily retrieved in or via the browser using mod_plsql. Simplified:
    select content, mime_type
    into v_blob, v_mime_type
    from ...
    owa_util.mime_header(nvl(v_mimetype,'application/octet'),false);
    htp.p('Content-length: ' || dbms_lob.getlength(v_blob));
    owa_util.http_header_close;
    wpg_docload.download_file(v_blob);So, the link in your report should point to this database procedure.
    Edited by: InoL on Mar 1, 2011 4:17 PM

  • Problem while updating excel file in Km

    Hai,
      I am using jxl api to generate excel file . I need to update the excel file. for that i am creating tht excel file in temp location , and updating using this code.
    excelFile=new File(fileName);
    embedDataIntoExcel();
    workbook.write();
    workbook.close();
    IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
              com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();
               IUser ep5User =WPUMFactory.getUserFactory().getEP5User(sapUser);
               ResourceContext context = new ResourceContext(ep5User);
               RID rid = RID.getRID("/path/excelFile.xls");
               IResourceFactory factory =ResourceFactory.getInstance();
               IResource folder = (IResource) factory.getResource(rid,context);
              FileInputStream fin = new FileInputStream(excelFile);
               fin.read();
               Content content = new Content(fin,"ms-excel", -1);
               folder.updateContent(content);
    <b>problem is the excel file is generating with some junk data </b>
    how can i solve this
    regards,
    naga

    Hai,
    I am using jxl api to generate excel file . I need to update the excel file. for that i am creating tht excel file in temp location , and updating using this code.
    excelFile=new File(fileName);
    embedDataIntoExcel();
    workbook.write();
    workbook.close();
    IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
              com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();
               IUser ep5User =WPUMFactory.getUserFactory().getEP5User(sapUser);
               ResourceContext context = new ResourceContext(ep5User);
               RID rid = RID.getRID("/path/excelFile.xls");
               IResourceFactory factory =ResourceFactory.getInstance();
               IResource folder = (IResource) factory.getResource(rid,context);
              FileInputStream fin = new FileInputStream(excelFile);
               fin.read();
               Content content = new Content(fin,"ms-excel", -1);
               folder.updateContent(content);
    problem is the excel file is generating with some junk data
    how can i solve this
    regards,
    naga

  • HOW TO - Create new from clipboard and process multiple files - please help

    Need help - have new version of photoshop on trial only ATM...
    Want to know - HOW TO:
    1. Create new from clipbaord
    2. Process multiple files
    Please help.

    For clipboard copy, I start with File > New and the size will be set to what's in the clipboard. Then once the new file is opened, Edit > Paste will place the clipboard contents as a layer in the new document.
    You must remember to use the command Layer > Flatten Image of you want to save as jpeg or any other file format that doesn't support layers.
    For processing multiple files,
    File > Automate > Batch or
    File > Scripts > Image Processor...
    Check the User guide or google information for those commands if you have specific needs.
    Gene

Maybe you are looking for

  • Cost Element missing in FAGLFLEXT for some PCA Plan records

    Hi Gurus, We have uploaded a PCA plan and can see the same in GP12NA. I see the planned values (GLPL) in FAGLFLEXT from SE16 under the correct accounts for 0L ledger for the correct company code and the fiscal year. I noticed a difference in the data

  • GUI_UPLOAD+HAS_FIELD_SEPARATOR

    Hi everybody . In my program, I use the fm GUI_UPLOAD to upload the flat file which separator is the pipe(|). Exemple of line :  AAA|BBB|CCC|DDD HAS_FIELD_SEPARATOR='|' not working, so how can i use this fm and define SEPARATOR  as pipe . thank  in a

  • Quark / PDF Printing Problems (Save as PDF in OS X)

    I upgraded from Quark 4.1 to 6.5 about a year ago, and ever since then the files I create and print don't look as good. The primary issue seems to be color -- colors don't come out as deep, there seems to be less color saturation, sometimes colors ar

  • Can't get substring to work properly

    I have one field called 'Name', you are supposed to put full name and list it like this, 'Last, First, MI' in this one field separated by a comma, for each name, ex., 'Doe, John A.'. I need to be able to extract the first initial from the last name,

  • Capturing the response received from the WCF web service method?

    Hi, I am trying to call a WCF web service method with input parameters in an xml file and then receive the returned output data by the web service as response into an xml file. So far I am able to call the webservice method successfully and not sure