Exported the JTable to excel  but to customize the excel file

Hi,
I have exported the JTable to excel through CSV file. But I want to customize the excel file, by setting border, color and cell styles. How to implement this? Can you please help me out?
Thanks,
public class CalculateUsers extends JPanel implements     ActionListener,     TableModelListener {
     JFrame frame;
     JTable table;
     public CalculateUsers(JPanel mainPanel) {
                rows = new Vector();
          columns = new Vector();
          String[] columnNames = {"BP","users","Avg","time"};
          addColumns(columnNames);
          tabModel = new DefaultTableModel();
          tabModel.setDataVector(rows, columns);
          table = new JTable(tabModel);
          table.getModel().addTableModelListener(this);
          lblMessage = new JLabel("");
             label1 = new JLabel("Textbox 1");
                label2 = new JLabel("Textbox 2");
                text1 = new JTextField(5);
          text2 = new JTextField(5);
          buttonPanel = new JPanel();
                    cmdAdd = new JButton("add");
                    cmdCalculate = new JButton("Calculate");
          cmdExportToExcel = new JButton("ExportToExcel");
                buttonPanel.add(label1);
          buttonPanel.add(text1);
          buttonPanel.add(label2);
          buttonPanel.add(text2);
          buttonPanel.add(cmdCalculate);
          buttonPanel.add(cmdExportToExcel);
          buttonPanel.add(cmdAdd);
     public void addRow() { // Add Row
          Vector r = new Vector();
          r = createBlankElement();
          rows.addElement(r);
                table.addNotify();
     public Vector createBlankElement() {
          Vector t = new Vector();
          t.addElement((String) " ");
          t.addElement((String) " ");
          t.addElement((String) " ");
          t.addElement((String) " ");
          t.addElement((String) " ");
          t.addElement((String) " ");
          t.addElement((String) " ");
             return t;
     public void calculate() throws Exception {
            int i = table.getRowCount();
            int firstCellVal, secondCellVal, thirdCellVal, fourthCellVal, fifthCell, sixthCell, sevenCell, eightCell,jtext1,jtext2;
           try{ 
                 tabModel.addColumn("Time taken");
             tabModel.addColumn("Pse");
             tabModel.addColumn("Users %");
             tabModel.setColumnCount(7);
                jtext1 = Integer.parseInt(text1.getText().toString().trim());
                jtext2 = Integer.parseInt(text2.getText().toString().trim());
              for (i = 0; i < table.getRowCount(); i++) {
                    String cell1 = table.getValueAt(i, 0).toString();
                    String cell2 = table.getValueAt(i, 1).toString();
                    String cell3 = table.getValueAt(i, 2).toString();
                    String cell4 = table.getValueAt(i, 3).toString();
                    sixthCell = secondCellVal * thirdCellVal * fourthCellVal;
                    sevenCell = ((jtext1 - (fourthCellVal * thirdCellVal))/(fourthCellVal - 1));
                    eightCell = (secondCellVal * 100)/jtext2;
                    table.setValueAt(result2, i, 4);
                    table.setValueAt(result3, i, 5);
                    table.setValueAt(result4, i, 6);
            } catch(Exception ae) {
                    ae.printStackTrace();
     public void actionPerformed(ActionEvent source) throws ArithmeticException { // ActionList
          if (source.getSource() == (JButton) cmdAdd) {
                    addRow();
          if (source.getSource() == (JButton) cmdCalculate) {
                      calculate();
          if (source.getSource() == (JButton) cmdExportToExcel) {
                     exportToExcel();
      private void exportToExcel() throws Exception{
               exportTable();
     *public void exportTable() { // export Table*
*          try {*
*               System.out.println("Exporting Table ");*
*               String filename = "ScenarioAutomation" + System.currentTimeMillis()+ ".CSV";*
*               File file = new File(filename);*
*               String data;*
*               String columnNames[] = null;*
*               columnNames = new String[table.getColumnCount()];*
*               if (file != null) {*
                            *try {*
*                    BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file, true));*
*                    PrintWriter fileWriter = new PrintWriter(bufferedWriter);*
*                    System.out.println("Column Headers ");*
*                    firstRowInExcel(fileWriter);*
*                    for (int j = 0; j < columnNames.length; j = j + 1) {*
*                        columnNames[j] = table.getColumnModel().getColumn(j).getHeaderValue().toString();*
*                        data = columnNames[j];*
*                        System.out.println("data " + data);*
*                        fileWriter.print(data + ",");*
                               *     System.out.println("Done.... ");*
                               *     fileWriter.println("");*
                               *     System.out.println("Exporting Data ");*
*                    for (int k = 0; k < table.getRowCount(); ++k) {*
                                    *for (int l = 0; l < table.getColumnCount(); ++l) {*
*                         data = table.getValueAt(k, l).toString();*
*                         fileWriter.print(data + ",");*
                                    *fileWriter.println("");*
*                    fileWriter.close();*
*                    System.out.println("Done.... ");*
*                    System.out.println("File Name " + filename);*
*                    open(file);*
*                    } catch (Exception e) {*
                                    *JOptionPane.showMessageDialog(null, "Error " + e);*
*          } catch (Exception E) {*
*               System.out.println("Error While Exporting Table " + E);*
*     private void firstRowInExcel(PrintWriter fileWriter) {*
                *fileWriter.println("");*
*          String jtext1label = ("Textbox 1");*
*          fileWriter.print(jtext1label);*
*          fileWriter.print(",");*
*          String jtext1Value = text1.getText();*
*          fileWriter.print(jtext1Value);*
*          fileWriter.print(",");*
*          fileWriter.print(" ");*
      *private void open(File f) {*
       *     String[] commands = {*
*          "rundll32",*
*          "url.dll,FileProtocolHandler",*
*          f.getAbsolutePath()*
*          try {*
                    *System.out.println("****OPEN file ****");*
                    *Runtime.getRuntime().exec(commands);*
*          } catch (IOException e) {*
                    *e.printStackTrace();*
*}*

for this purpose you need to took help of the third party APIs.
try POI from Apache
http://poi.apache.org/hssf/index.html
this is easy and efficent. and Free also.
one more i found is
http://es.actuate.com/xlsjbook/apibasics.html (Not sure about this one.)
good luck go ahead

Similar Messages

  • "Content generation error. Failed to Export the PDF file"

    Building a multi-folio in InDesign 6 Folio Builder V30. Received "Content generation error. Failed to Export the PDF file" on several of the spreads. I have tried reducing the original pdf files sizes, but that did not help.
    Any suggestions on other possible causes or way to fix.?
    thanks
    Christopher Huber
    MMN

    I'm very new to DPS so I hope the following description makes some kind of sense.
    My magazine is in the process of doing trial runs for an iPad edition. I'm setting some templates up for us to work off so the process from magazine to iPad will run a lot smoother month to month.
    So far I've set up some dummy stock pages in an InDesign CS6 document, currently 15 pages long.
    All images are linked and all fonts have paragraph styles applied to them.
    I'm at the stage I want to check the document on my iPad to test run font sizes and their legibility.
    We have successfully been able to export the document as a jpg file but we really need the PDF format. When attempting this we get the above message.
    Sonia.

  • Problem is when iam exporting the jar file the manifest file  chaning

    LogWriter.java
    MiniBrowser.java
    SendMail.java
    TestMiniBrowser.java
    iam running the site scope program ,program is running fine
    i add the mail.jar and activation.jar
    when iam Exporting the JAR file ,the Manifest files is changing with out classpath
    only showing the like this
    Manifest-Version: 1.0
    Sealed: true
    Main-Class: p1.TestMiniBrowser
    Actually i created the manifest files like this ..
    Manifest-Version: 1.0
    Sealed: true
    Class-Path: mail.jar activation.jar icsops.jar
    Main-Class: p1.TestMiniBrowser
    problem is when iam exporting the jar file the manifest file is changing then iam not able the run the jar file ..

    iam Useing Eclipse sdk3.1
    after exporing the jar the manifewst is canging but iam updating mauvally but when iam runingg the jar file
    D:\pavansitescope>set calsspath=%classpath%C:\j2sdk1.4.1_03\bin;.;
    D:\pavansitescope>set calsspath=%classpath%D:\pavansitescope\mail.jar;.;
    D:\pavansitescope>set calsspath=%classpath%D:\pavansitescope\activation.jar;.;
    D:\pavansitescope>set calsspath=%classpath%D:\pavansitescope\mail-plugin.jar;.;
    D:\pavansitescope>java -jar icsops.jar
    Arguments Usage:
    1. URL link
    2. From Address
    3. To Addresses (seperated by comma)
    4. Mail Server Host Name
    D:\pavansitescope>java -jar icsops.jar [http://69.27.230.104/SiteScope/accounts/l]
    ogin5/htdocs/Progress.html [[email protected]|mailto:[email protected]] [[email protected]|mailto:[email protected]] HYDMA
    IL03
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingE
    xception
    at p1.TestMiniBrowser.start(TestMiniBrowser.java:42)
    at p1.TestMiniBrowser.main(TestMiniBrowser.java:156)
    D:\pavansitescope>

  • When you create a link to a web page in numbers and we export the PDF file, the link is offset by 3 rows. Example: if I put a link on the text in cell A1, I found the link A4. In fact, this feature becomes unusable. How can we solve this problem? Thank yo

    When you create a link to a web page in numbers "Mavericks" and we export the PDF file, the link is offset by 3 rows. Example: if I put a link on the text (with Cmd-K) in cell A1, I found the link A4. In fact, this feature becomes unusable. How can we solve this problem?
    Thank you.

    Hi again Raja!
    I did as you recommended and installed HTTPWatch and below is the outcome of that program. It is the exact string with the only exception of obfuscated servernames and portnumbers. The last part that begins with "sap_ep_baseurl=" makes me suspicious, is that part really correct? It looks like it's lacking things.
    Best regards
    Benny
    http://<server:port>/sap/bc/bsp/sap/Z_PURCHASE_REQ/process.htm?
    sap-syscmd=nocookie&sap-client=200&sap-language=sv&style_sheet=
    http%3A%2F%2F<server>%3A<port>%2Firj%2Fportalapps%2F
    com.sap.portal.design.portaldesigndata%2Fthemes%2Fportal%2Fsap_tradeshow%2F
    controls%2Fcontrols_ie6.css%3F7.0.10.0.0&sap-cssversion=7.0.10.0.0&sap-tray-type
    =null&sap-tray-padding=null&sap-accessibility=&sap-ep-version=7.00.200611091758&
    sap_ep_version=7.00.200611091758&sap_ep_baseurl=http%3A%2F%2F
    <server>%3A<port>%2Firj%2Fportal&matnr=9780198603641

  • Failed to export the JPEG file

    When I attempt to export a jpeg from InDesign I get the following error message, please help:
    "Failed to export the JPEG file: File cannot be written.
    Disc may be locked or full."
    The disc it is writing to has 90Gb of memory free and I've tried knocking the quality of the export down with no success.
    I am running CS6 on a fully updated Macbook Pro.
    Thanks.

    I'm trying to export to the hard drive on the Mac as usual, and have never had this issue before?

  • InDesign CS6 "Failed to export the JPEG file. File cannot be written. Disk may be locked or full."

    I get this error "Failed to export the JPEG file. File cannot be written. Disk may be locked or full." when sending small (3"x3") and large (40"x60") files to a printer hot folder. Sometime if I close the program and restart it will let me export. What could be causing this to happen?
    I am on Windows 7 with 4GB RAM PC.

    I guess the printer is grabbing the file before it is entirely written…
    Workaround: Do not save to a hot folder. Move the files after exporting to the hot folder.
    Uwe

  • Content generation error. [Error: Failed to Export the PDF file.]

    Hi;
    Everytime i try to update an article within a folio in DPS folio builder i get this error :
    Content generation error.
    [Error: Failed to Export the PDF file.]
    My colleague next to me is running exactly the same set up and doesnt get the error. in fact his update anf sideloading is fast as lightning.
    the ONLY difference is that im running v28 tools and he is on v27, however wehave another colleague running v28 and his updates work perfectly.
    Any ideas lovely community?
    Scott

    Hi Bob;
    Have tried that one. And again on your suggestion....no luck.
    Scott

  • Export the pdf from indesign some error Pop Up window (Failed to Export the PDF file). How slove the

    Export the pdf from indesign some error Pop Up window (Failed to Export the PDF file). How slove the problem
    Please some one help on this

    You need to try exporting the first half of the book.
    If that exports ok then export the other half of the book.
    Whatever half it fails on - keep dividing the book in half to find the culprit page or pages.
    For example if your book is 128 pages long:
    1. Export pages 1 - 63
    2. If these Fail to Export then
    3. try exporting1-32
    4. If these Fail to Export
    5. then try exporting1-16
    If it doesn't fail (step 2)
    Then export pages 64-128
    and 64-90 etc.
    until you find the pages causing the issues.

  • I am trying to export the PDF file and conversion fails every time.

    I am trying to export the PDF file and conversion fails every time. File is too large of too complex. What do I do? One file is about 55 mb and the other is 58 mb.

    Try extracting part of the file and see if the extracted part can be Exported. If so, repeat with the next set of pages. When done, try to load all into the first file.

  • Possible exporting the answer file AND attachments ALSO ONLY A transaction in a directory ?

    Possible exporting the answer file "Form" AND attachments ALSO ONLY A transaction in a directory ?
    Est-il possible de télécharger (d'exporter) en une seule opération le fichier-réponse à un formulaire ADOBE et toutes ses pièces jointes dans un dossier et ceci en une seule opération ? Merci.

    Thank you. Cepha.
    De : SumitV <[email protected]<mailto:[email protected]>>
    Répondre à : "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
    Date : mardi 16 décembre 2014 11:06
    À : Bernard VIVIER <[email protected]<mailto:[email protected]>>
    Objet : You have been mentioned by SumitV in Re: Possible exporting the answer file AND attachments ALSO ONLY A transaction in a directory ? in Adobe Community
    You have been mentioned
    by SumitV<https://forums.adobe.com/people/SumitV?et=notification.mention>in Re: Possible exporting the answer file AND attachments ALSO ONLY A transaction in a directory ? in Adobe Community - View SumitV's reference to you<https://forums.adobe.com/message/7018753?et=notification.mention#7018753>

  • Exporting Tcode MKVZ to Excel File

    Hi Experts,
    I'm trying to export the output of tcode MKVZ (List of Vendors: Purchasing) to a local file in the format of spreadsheet. I successfully exported the file but when I reviewed the content on the excel file, some rows were missing and others were merge to other rows.
    Please help me how can I export it properly on spreadsheet.
    Regards,
    Ronald

    Hi  Jürgen,
    Your guess is absolutely right.  I'm connecting to the sap system remotely so that's why I need to export it locally. Then, I choose the format spreadsheet. By default on the filename, there was already a .XLS extension, so I only need to add the name of the file then click the generate button. It was successfully generated. When I tried to open it on the excel, it always prompts me that the file I'm going to open is in a different format than the specified by the file extension. Still, I ignored the warning message since the excel file can read and open the file. But the data format was not on the right rows or columns.
    Now I understand that it should be in a txt format before I import it to an excel file. But how come that the spreadsheet is not an excel format? I thought it is a format of excel.
    Thanks so much for your help, assistance and patience.
    Cheers!
    Ronald

  • How to export report output into excel file

    hi friends,
    i would like to get the solution from you for how to export the report output into a .xls file. i know how to convert it into .rtf and .txt files but i think it's difficult to do this .xls way, could you help me to comeover this problem?
    thankyou very much.

    The official answer is "delimited", which
    generates adequate comma or other delimited
    text. No formatting, and without extra
    effort no support for non-ASCII characters.
    Might be sufficient for you.
    Note that Excel can read html files - we
    built programs to generate html files with
    name of "blah.xls" and some Excel-ish
    extensions, so Excel is automatically opened
    and the document is all nice and pretty.
    (Oracle html output has some odd logic about
    choosing number of columns, we didn't use
    it.)
    -- Allan Plum

  • Export properties to an Excel file

    Hello,
    Is it possible to export all properties of each page and Iview to an Excel file?
    Greetings,
    Gene

    Hi Gene,
    No, but the documentation is MUCH better than three years ago :-] (there was no doc at all about these things, and nevertheless we started to develop such things and more).
    Get used to it, and you will gain some knowledge you will be able to re-use for other problems...
    Hope it helps
    Detlev

  • How to export data to an excel file using VBScript

    I'm trying to create a VBScript in DIAdem (V9.1) which automatically saves all the current channels in the data portal to an excel file. I've tried using 'Call ExcelExport' and specify a full file path but the file is never created. What am I doing wrong?
    Thanks,
    Steve

    Hi Steve,
    There are a couple of other things you can try. If you don't like Ingo's suggestion about multiple Excel STP files, your only real option is to create an ASCII file. Note that you can give the ASCII file an extension of *.CSV or even *.XLS, and Excel will read it right in.
    So the question boils down to how to format the ASCII export correctly and quickly.
    You can use the DAT file approach Ingo mentioned and even re-write the file with VBS to include a few header lines of your own choosing. Note that this approach does NOT support text channels. There is an example of this in the zip file attached below.
    You can alternatively use the CSV export function in DIAdem 9.1 to output an ASCII file with the name of each channel as the single header row above all the values. There is an example of this in the zip file attached below.
    You can also just read the values from the DIAdem channels and write them out to an ASCII file cell by cell, managing everything with VBScript calls. There is an example of this in the zip file attached below.
    I hope that helps,
    Brad Turpin
    DIAdem Product Support Engineer
    National Indstruments
    Attachments:
    DIAdem ASCII Export.zip ‏5 KB

  • Exporting cube data to Excell file

    hi Experts,
    i want to export the data from cube which has more than 1 lakh.How it stores in Excel file it aloows max 65000 records  for each sheet.how can we able to send to another sheet the remaining data.Iam exporting from Manage cube.
    bye
    venkat

    Hi,
      its not like that excel will show you only 65k lines, you can just export the file into excel and open it in editor or import it into access and work on it. but dont open file in excel and save it, it will save only 65k lines only.
    Regards
    Sankar

  • How can I print out all notes or export the entire file?

    I have around 300 notes that include a variety of information. I would like to print out a hard copy. I don't want to open and print out each one individually. Is there a way to print out all of them at once. Also, is there a way export the file so I can open it in another application like Excel or Word?

    It's not a file, so you can't "open" one file. Every message (and note) is a single file on the computer.
    This Applescript will grab all the notes in the selected mailbox (i.e. the selected Notes item in Mail) and put them in a textEdit document.
    Note that Mail doesn't differentiate between a note and an email message, so if you run this while a normal email mailbox is selected, it will gather all of your email messages.
    tell application "Mail"
    set theMailboxes to the selected mailboxes of message viewer 0
    repeat with aMailbox in theMailboxes
    set theNotes to the messages of aMailbox
    set theText to ""
    repeat with aNote in theNotes
    set theText to theText & content of aNote & return
    end repeat
    end repeat
    end tell
    tell application "TextEdit"
    set myDocument to make new document at end of documents with properties {text:theText}
    end tell
    Copy and paste this into a new AppleScript Editor Document, select the Notes mailboxes you want to print the notes from, and click the Run button (Green button with arrow).
    This may take a while.

Maybe you are looking for