Help needed saving excel file using servlet and mailing it as attachment

Hi,
I have to enhance an existing application in which (in jsp) using response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment=inline");
and stuff ..
we are asking user to view or save the file. But now i have to write code to save that xls, and send it as an attachment to other users of the application.
I am new to this plz help me out
Thanks in advance
Regards
Aashi

Hi Orlando,
convert content to Hex format then,
lw_document = cl_document_bcs=>create_document(
           i_type    = 'RAW / HTM'
           i_text    = lw_main_text
           i_subject = lw_subject ).
      w_document->add_attachment(
         i_attachment_type    = 'XLS'
         i_attachment_subject = lw_att_sub
         i_att_content_text   = p_int_soli[]
         i_att_content_hex    = p_int_solix[] ).
w_int_address = lw_smtp-low.
             w_camuser = cl_cam_address_bcs=>create_internet_address( w_int_address ).
             w_recipient = w_camuser.
thanks,
Anil

Similar Messages

  • Upload an excel file using servlet

    want to upload an excel file read it and do some updates and then again build an excel sheet
    step 1: display an Excel sheet inside the browser
    step 2: edit the sheet
    step 3: send the sheet data to a Servlet to read it.
    i am using POI to read an excel file and use POIFS
    when i upload an excel file and get servletinputstream it gives the header+data+tailor
    stand alon i have done it but using servlet i failed
    can anybody give me an simple example to upload an excel file and shoe it
    plz help me

    Surprise! Look what the forum says...
    BEFORE YOU POST A TOPIC HERE: Please be sure your topic is related to features or functionality of this site. This forum is not for general technology questions. Not sure which forum to use? Try searching for your topic in the "Search Forums" element on the left panel.Please post your question on http://forum.java.sun.com/forum.jspa?forumID=33
    Do not reply here.

  • Help needed:Printing HTML file using javax.print

    Hi
    I am using the following code which i got form the forum for rpinting an HTML file.
    The folllowing code is working fine, but the problem is the content of HTML file is not getting printed. I am geeting a blank page with no content. What is the change that is required in the code? ALso is there any simpler way to implement this. Help needed ASAP.
    public boolean printHTMLFile(String filename) {
              try {
                   JEditorPane editorPane = new JEditorPane();
                   editorPane.setEditorKit(new HTMLEditorKit());
                   //editorPane.setContentType("text/html");
                   editorPane.setSize(500,500);
                   String text = getFileContents(filename);
                   if (text != null) {
                        editorPane.setText(text);                    
                   } else {
                        return false;
                   printEditorPane(editorPane);
                   return true;
              } catch (Exception tce) {
                   tce.printStackTrace();
              return false;
         public String getFileContents(String filename) {
              try {
                   File file = new File(filename);
                   BufferedReader br = new BufferedReader(new FileReader(file));
                   String line;
                   StringBuffer sb = new StringBuffer();
                   while ((line = br.readLine()) != null) {
                        sb.append(line);
                   br.close();
                   return sb.toString();
              } catch (Exception tce) {
                   tce.printStackTrace();
              return null;
         public void printEditorPane(JEditorPane editorPane) {
                   try {
                        HTMLPrinter htmlPrinter = new HTMLPrinter();
                        htmlPrinter.printJEditorPane(editorPane, htmlPrinter.showPrintDialog());
                   } catch (Exception tce) {
                        tce.printStackTrace();
         * Sets up to easily print HTML documents. It is not necessary to call any of the setter
         * methods as they all have default values, they are provided should you wish to change
         * any of the default values.
         public class HTMLPrinter {
         public int DEFAULT_DPI = 72;
         public float DEFAULT_PAGE_WIDTH_INCH = 8.5f;
         public float DEFAULT_PAGE_HEIGHT_INCH = 11f;
         int x = 100;
         int y = 80;
         GraphicsConfiguration gc;
         PrintService[] services;
         PrintService defaultService;
         DocFlavor flavor;
         PrintRequestAttributeSet attributes;
         Vector pjlListeners = new Vector();
         Vector pjalListeners = new Vector();
         Vector psalListeners = new Vector();
         public HTMLPrinter() {
              gc = null;
              attributes = new HashPrintRequestAttributeSet();
              flavor = null;
              defaultService = PrintServiceLookup.lookupDefaultPrintService();
              services = PrintServiceLookup.lookupPrintServices(flavor, attributes);
              // do something with the supported docflavors
              DocFlavor[] df = defaultService.getSupportedDocFlavors();
              for (int i = 0; i < df.length; i++)
              System.out.println(df.getMimeType() + " " + df[i].getRepresentationClassName());
              // if there is a default service, but no other services
              if (defaultService != null && (services == null || services.length == 0)) {
              services = new PrintService[1];
              services[0] = defaultService;
         * Set the GraphicsConfiguration to display the print dialog on.
         * @param gc a GraphicsConfiguration object
         public void setGraphicsConfiguration(GraphicsConfiguration gc) {
              this.gc = gc;
         public void setServices(PrintService[] services) {
              this.services = services;
         public void setDefaultService(PrintService service) {
              this.defaultService = service;
         public void setDocFlavor(DocFlavor flavor) {
              this.flavor = flavor;
         public void setPrintRequestAttributes(PrintRequestAttributeSet attributes) {
              this.attributes = attributes;
         public void setPrintDialogLocation(int x, int y) {
              this.x = x;
              this.y = y;
         public void addPrintJobListener(PrintJobListener pjl) {
              pjlListeners.addElement(pjl);
         public void removePrintJobListener(PrintJobListener pjl) {
              pjlListeners.removeElement(pjl);
         public void addPrintServiceAttributeListener(PrintServiceAttributeListener psal) {
              psalListeners.addElement(psal);
         public void removePrintServiceAttributeListener(PrintServiceAttributeListener psal) {
              psalListeners.removeElement(psal);
         public boolean printJEditorPane(JEditorPane jep, PrintService ps) {
                   if (ps == null || jep == null) {
                        System.out.println("printJEditorPane: jep or ps is NULL, aborting...");
                        return false;
                   // get the root view of the preview pane
                   View rv = jep.getUI().getRootView(jep);
                   // get the size of the view (hopefully the total size of the page to be printed
                   int x = (int) rv.getPreferredSpan(View.X_AXIS);
                   int y = (int) rv.getPreferredSpan(View.Y_AXIS);
                   // find out if the print has been set to colour mode
                   DocPrintJob dpj = ps.createPrintJob();
                   PrintJobAttributeSet pjas = dpj.getAttributes();
                   // get the DPI and printable area of the page. use default values if not available
                   // use this to get the maximum number of pixels on the vertical axis
                   PrinterResolution pr = (PrinterResolution) pjas.get(PrinterResolution.class);
                   int dpi;
                   float pageX, pageY;
                   if (pr != null)
                        dpi = pr.getFeedResolution(PrinterResolution.DPI);
                   else
                        dpi = DEFAULT_DPI;
                   MediaPrintableArea mpa = (MediaPrintableArea) pjas.get(MediaPrintableArea.class);
                   if (mpa != null) {
                        pageX = mpa.getX(MediaPrintableArea.INCH);
                        pageY = mpa.getX(MediaPrintableArea.INCH);
                   } else {
                        pageX = DEFAULT_PAGE_WIDTH_INCH;
                        pageY = DEFAULT_PAGE_HEIGHT_INCH;
                   int pixelsPerPageY = (int) (dpi * pageY);
                   int pixelsPerPageX = (int) (dpi * pageX);
                   int minY = Math.max(pixelsPerPageY, y);
                   // make colour true if the user has selected colour, and the PrintService can support colour
                   boolean colour = pjas.containsValue(Chromaticity.COLOR);
                   colour = colour & (ps.getAttribute(ColorSupported.class) == ColorSupported.SUPPORTED);
                   // create a BufferedImage to draw on
                   int imgMode;
                   if (colour)
                        imgMode = BufferedImage.TYPE_3BYTE_BGR;
                   else
                        imgMode = BufferedImage.TYPE_BYTE_GRAY;
                   BufferedImage img = new BufferedImage(pixelsPerPageX, minY, imgMode);
                   Graphics myGraphics = img.getGraphics();
                   myGraphics.setClip(0, 0, pixelsPerPageX, minY);
                   myGraphics.setColor(Color.WHITE);
                   myGraphics.fillRect(0, 0, pixelsPerPageX, minY);
                        java.awt.Rectangle rectangle=new java.awt.Rectangle(0,0,pixelsPerPageX, minY);
                   // call rootView.paint( myGraphics, rect ) to paint the whole image on myGraphics
                   rv.paint(myGraphics, rectangle);
                   try {
                        // write the image as a JPEG to the ByteArray so it can be printed
                        Iterator writers = ImageIO.getImageWritersByFormatName("jpeg");
                        ImageWriter writer = (ImageWriter) writers.next();
                                       // mod: Added the iwparam to create the highest quality image possible
                        ImageWriteParam iwparam = writer.getDefaultWriteParam();
                        iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;
                        iwparam.setCompressionQuality(1.0f); // highest quality
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        ImageOutputStream ios = ImageIO.createImageOutputStream(out);
                        writer.setOutput(ios);
                        // get the number of pages we need to print this image
                        int imageHeight = img.getHeight();
                        int numberOfPages = (int) Math.ceil(minY / (double) pixelsPerPageY);
                        // print each page
                        for (int i = 0; i < numberOfPages; i++) {
                             int startY = i * pixelsPerPageY;
                             // get a subimage which is exactly the size of one page
                             BufferedImage subImg = img.getSubimage(0, startY, pixelsPerPageX, Math.min(y - startY, pixelsPerPageY));
                                                 // mod: different .write() method to use the iwparam parameter with highest quality compression
                             writer.write(null, new IIOImage(subImg, null, null), iwparam);
                             SimpleDoc sd = new SimpleDoc(out.toByteArray(), DocFlavor.BYTE_ARRAY.JPEG, null);
                             printDocument(sd, ps);
                             // reset the ByteArray so we can start the next page
                             out.reset();
                   } catch (PrintException e) {
                        System.out.println("Error printing document.");
                        e.printStackTrace();
                        return false;
                   } catch (IOException e) {
                        System.out.println("Error creating ImageOutputStream or writing to it.");
                        e.printStackTrace();
                        return false;
                   // uncomment this code and comment out the 'try-catch' block above
                   // to print to a JFrame instead of to the printer
                   /*          JFrame jf = new JFrame();
                             PaintableJPanel jp = new PaintableJPanel();
                             jp.setImage( img );
                             JScrollPane jsp = new JScrollPane( jp );
                             jf.getContentPane().add( jsp );
                             Insets i = jf.getInsets();
                             jf.setBounds( 0, 0, newX, y );
                             jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
                             jf.setVisible( true );*/
                   return true;
              * Print the document to the specified PrintService.
              * This method cannot tell if the printing was successful. You must register
              * a PrintJobListener
              * @return false if no PrintService is selected in the dialog, true otherwise
              public boolean printDocument(Doc doc, PrintService ps) throws PrintException {
                   if (ps == null)
                   return false;
                   addAllPrintServiceAttributeListeners(ps);
                   DocPrintJob dpj = ps.createPrintJob();
                   addAllPrintJobListeners(dpj);
                   dpj.print(doc, attributes);
                   return true;
              public PrintService showPrintDialog() {
                   return ServiceUI.printDialog(gc, x, y, services, defaultService, flavor, attributes);
              private void addAllPrintServiceAttributeListeners(PrintService ps) {
                   // add all listeners that are currently added to this object
                   for (int i = 0; i < psalListeners.size(); i++) {
                   PrintServiceAttributeListener p = (PrintServiceAttributeListener) psalListeners.get(i);
                   ps.addPrintServiceAttributeListener(p);
              private void addAllPrintJobListeners(DocPrintJob dpj) {
                   // add all listeners that are currently added to this object
                   for (int i = 0; i < pjlListeners.size(); i++) {
                   PrintJobListener p = (PrintJobListener) pjlListeners.get(i);
                   dpj.addPrintJobListener(p);
              // uncomment this also to print to a JFrame instead of a printer
              /* protected class PaintableJPanel extends JPanel {
                   Image img;
                   protected PaintableJPanel() {
                        super();
                   public void setImage( Image i ) {
                        img = i;
                   public void paint( Graphics g ) {
                        g.drawImage( img, 0, 0, this );
    Thanks
    Ram

    Ram,
    I have had printing problems too a year and a half ago. I used all printing apis of java and I still find that it is something java lacks. Now basically you can try autosense. To check whether your printer is capable of printing the docflavor use this PrintServiceLookup.lookupPrintServices(flavor, aset); . If it lists the printer then he can print the document otherwise he can't. I guess that is why you get the error.
    Regards,
    Kevin

  • Saving excel file using HSSF api

    I am using HSSF api to download an excel file. But the end users are not able to save the file. Some of them do not get the popup file download window so that they can choose to open or save. Is there a setting in the browser which shows up the window? The users may have different versions of excel on their pcs.
    How to show the excel application menu 'file' so that users can save this file?
    Any help would be appreciated.

    Prakash,
              I have followed your weblog and set the content dispostion.
    HttpServletResponse res = request.getServletResponse(true);
                   try {
                        res.setContentType("application/vnd.ms-excel");
                        res.setHeader("Content-disposition", "inline; filename=report.xls");
                        wb.write(res.getOutputStream());
                   } catch (Exception e) {
                        e.printStackTrace();
    When I test this on my pc, I get file download window and I can choose 'open' or'save'. I also have tested this on some of my collegues PCs successfully. But the some of the end users are not getting this window.
    when the same is file is downloaded by running an asp page the enire MSExcel application with standard tool bar and menus(file edit etc..) is showing up.
    Why is it not poosible to get the same result using HSSF api?

  • Help needed in splitting files using BPM

    Hello experts,
    I am working on an interface where i need to split files within BPM.
    I know,i can achieve it in Message Mapping by mapping Recordset to Target structure and then using Interface Mapping within Transformation step.But i dont want to follow this.Is there an alternative way to achieve this within BPM.
    I have an input file with multiple headers and i need to split for each header.My input file looks like this:
    HXXXXXABCDVN01
    MXXXXXXXXXXXXXX
    MXXXXXXXXXXXXXX
    SXXXXXXXXXXXXXX
    HXXXXXABCDVN02
    MXXXXXXXXXXXXXX
    MXXXXXXXXXXXXXX
    SXXXXXXXXXXXXXX
    HXXXXXABCDVN03
    MXXXXXXXXXXXXXX
    SXXXXXXXXXXXXXX
    Is there a way, where i can specify this condition within BPM , that split files for every H.
    Thanks in advance.
    Regards,
    Swathi

    Hi,
    have your target structure with occurence as 0...unbounded in the mapping and map the header filed to the root node (repeating parent node) of the target structure....this will create as many target messages as the header fileds....if you want to send these messages separately then use a block in BPM with ForEach option....
    Splitting and Dynamic configuration can be applied in the same mapping.
    Regards,
    Abhishek.
    Edited by: abhishek salvi on Dec 18, 2008 12:59 PM

  • Help needed- Caller tone application using JTAPI and JMF

    Hi to All,
    I want to make a Caller Tone Application for Cisco IP phone.
    For that application I am using JTAPI and JMF.
    I am new to this two technologies.
    Can somebody help me for how to accomplish this?
    ---Ashish

    Hi Jerry,
    You can run analog input and counter tasks concurrently.  You can start them using software timing basically at the same time which may be fine for your needs and is the easiest to implement.  You also can use a hardware start trigger to start the tasks if you prefer.  It all depends on the level of synchronization you need. 
    You have not mentioned at what rate you will be acquiring data on your analog inputs.  The M Series PCI-6225 has 80 analog inputs and may suit your needs.  You will need to know what sampling rate you are trying to achieve.  Any M Series device will definitely give you the best value. 
    Hope this helps!
    Laura

  • Download local file using Servlet and JSP

    Hello,
    I will like to use a browser to download file on local system using serlvet and Jsp technology. Does anyone have any idea how to do it?
    Any comment will be appreciate.
    Thanks

    Well you can just put the file in a folder that is accessible to the web server. Then have a link point to that file. That will cause the web browser to download the file.
    hattan

  • How to read a file using servlet

    hi ,
    i've to read a file using servlet ,
    should read the file using servlet and display it in JSP,Could anybody get me how can i do it .
    Shiva

    To do that you need to get the response output stream and write yur file contents to that.
    response.setContentType(mimeType); //Set the mime type for the response
    ServletOutputStream sos = resp.getOutputStream();
    sos.write(bytes from your file input stream);
    sos.close();

  • Can't burn dvd that plays on dvd player. seems to be in file format. do i need extra software? using iMovie and final cut pro trail..both same result. have macbook pro 2012

    can't burn dvd that plays on dvd player. seems to be in file format. do i need extra software? using iMovie and final cut pro trail..both same result. have macbook pro 2012

    NStrange wrote:
    ... confused about which video format(s) to use (e.g.: SWF, MPEG4, etc.), and whether or not I should use 3rd party compression software (e.g.: Sorenson Squeeze, Compression Master, etc.) along with / in addition to Final Cut Express (among other similar issues)...
    FC/e is based upon the Quicktime-engine; so, on 'Export using QT', you'll get all codecs & settings.
    but which one..
    due to sheer popularity, YouTube became a 'standard' - I'm happy with the convenience, YT and the 'embed'-code offers - excellent quality, automatic adjusted to the watchers connection&hardware.
    my export settings are 720p, h264, 6MBit/sec - gives a - imho! - superb quality.
    (example of a 'screen-test' from my latest project CLICK )
    for creating so-called 'flash video'/.flv, you need 3rd party apps.
    Sorenson Squeeze is more of an pro-tool, .. you need some background knowledge to get noticeable 'better' quality.
    .. and the question is: are you willing to pay $.$$$ for that 0.x% more quality .. ? does your source offers such a 101% quality, which needs such affords?
    if bandwidth is an issue, because you're hosting on your own servers, consider the free codec xh264, you can install as a free QT-plug-in.. with low or super-low bitrates, it offers a superior quality compared to h264 ...

  • Need help-problem importing excel files

    I am about to begin work on an annual report that will involve importing charts and tables from an Excel file. I am able to drag and drop the pie charts and bar graphs into Indesign. When I try to do the same with the tables, they don't come across. When I import the excel file using the "place" command in Indesign , the files comes through as text only. I need the chart design and formatting. Any ideas?

    If this is going to press then you absolutely should bring those charts into Illustrator. At the very least you want to make sure to convert the RGB black text to real black.
    As for the tables, when you place the Excel file, make sure that show options is selected in the place dialog box. Then choose the proper formatting for the table. If you already formatted everything in Excel, choose Formatted Table. I think you'll be fairly pleased.
    Bob

  • URGENT.........File Upload using Servlets and jsp

    I am a new servlet programmer.......
    iam using tomcat server......
    can any one pls help in writing code for file upload using servlets and jsp without using multipart class or any other class like that....
    Please URGENT..

    Slow down! "Urgent" is from your perspective alone. I, myself, am not troubled or worried in the least.
    hi ugniss
    thanks for ur reply....sorry i was not
    y i was not asked not to use multipart class or any
    other class like that...is there any other
    possibility to do file uploading from jsp to
    servlet...
    Just as an aside, a JSP is a Servlet. But even if I move beyond that, the question does not make sense. If you want a "JSP to upload to a Servlet", then simply do so in memory. You are still (likely) within the same scope of a given request. However, if instead you are referring to a JSP that is displayed on a browser, then really you are talking about HTML, which is what the browser will receive. And since you are now talking about a browser, your only real, viable option is a multi-part file upload. So, it is either server or it is browser. And either way, the question leads to very established options, as outlined above.
    the main concept is.. in the browser the user selects
    a particular file and clicks the button upload..after
    clicking upload the jsp should sent the file to the
    servlet in streams...there the servlet gets in and
    saves in a server location........this is wat i hav
    to do...
    Okay. So, after reading my previous (redundant) paragraph, we have arrived at the crux of the issue. You have a JSP that will be output as HTML to a client (browser) which you want to upload content to your server (handled by a Servlet). So, you are now stuck again with multi-part. The requirement to not use multi-part is non-sensical. You can overcome it, say, if you write your own applet or standalone Swing client. However, if your users are invoking this functionality from a browser, you are limited by the options that W3C has provided you. Use multi-part.
    is there aby possibilty to do this.....can any one
    pls help....Take the advice to download and review Jakarta Commons FileUpload. Inform your management that their requirement makes no technical sense. Research on your own. There are dozens of examples (and tutorials) on file upload using multi-part. Embrace it. Live it. Love it.
    - Saish

  • How can I create an csv/excel file using pl/sql and then sending that file

    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.

    968776 wrote:
    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.You are trying to do it at a wrong place..
    Whay do you want database (pl/sql) code to do these things?
    Anyhow, you may be interested in :
    {message:id=9360007}
    {message:id=9984244}

  • Urgent help needed - new to Macs, accidently cut and paste over top of photo folder and now no sign of folder or file, no auto back-up in place, how can I restore photos pls

    Urgent help needed - new to Macs, accidently cut and paste over top of photo folder and now no sign of folder or file, no auto back-up in place, how can I restore photos pls

    Thanks for prompt reply, yes we have tried that but have now closed down the browser we where the photos were.
    We haven't sent up time machine, do you know whether there is any roll-back function on a Mac?
    Thanks

  • I saved an Excel file yesterday afternoon, and when I opened it today, all the formatting was lost.

    I saved an Excel file yesterday afternoon, and when I opened it today, all the formatting was lost.

    See:
    *[[/questions/894442]] OWA 2010/Firefox 8 and ASHX Attachments
    *[[/questions/895024]]

  • Writing into Excel file using PL/SQL and formatting the excel file

    Hi,
    I am writing into a excel file using PL/SQL and I want to make the first line bold on the excel. Also let me know if there are any other formatting options when writing into excel.
    Regards,
    -Anand

    I am writing into a excel file using PL/SQL
    Re: CSV into Oracle and Oracle into CSV
    check that thread or search in this forum...

Maybe you are looking for

  • Create material master get error message

    Hello Guys, I get the error message as below when i create material master .  can you help me?  error message nternal error in FORM/FUNCTION ckms_buffer_write in position 19 with RC 0 Message no. C+099 Procedure Please inform your system administrato

  • Firefox not firing the IOErrorEvent

    Firefox not firing the IOErrorEvent when load fails due to unavailability of internet connection in URLLoader. I am loading data in my application based on user actions. If the user is disconnected and he makes a request for data load, the IOErrorEve

  • Quicktime movies in 4.3?

    I have a 16.9 Pal dv timeline with the correct settings but when i export as a Qtime movie it comes out as 4.3. What's going on?

  • Can't see any tumbnails, Can't create proxy.

    Hello, I'm new into the FCS support and I do have a problem now with my FinalCutServer version 1.5.2 running on an Xserver with V-trak. First of all everything was running correctly but after some one did "propagate permissions" on my root harddrive

  • Y-intercept calculation problem: "A2:A7" isn't a valid reference

    This is actually a problem I have with many calculations in Numbers but I will use the following as an example: I am trying to calculate the y-intercept and slope for a set of data. Table 1 contains the raw data with each data point in triplicate. In