JTable & Excel

Hi,
I'd like to know how is possible to copy cells from Excel and paste them into a JTable.
Thanks

hi,you can copy data from a excel cell into a textfield.also it should work to copy it in a JTable cell.what Datatype it is is the Question,text i think. try it.the JTable must be editable.

Similar Messages

  • Export JTable to Excel

    Hi,
    I am trying to export a jtable to excel by using APACHE POI (latest version 3.6), but after adding the jar file to my CLASSPATH, my code will recognize all the new objects, which is great, but it wont find the "write" method from the HSSFWorkbook object. When I try to compile the code below, it gives me the following error:
    cannot find symbol
    symbol  : method write(java.io.FileInputStream)
    location: class org.apache.poi.hssf.usermodel.HSSFWorkbook
    wb.write(streamIn);
    //only import regarding the microsoft excel class
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    public void exportExcelTable()
       try{
            HSSFWorkbook wb = new HSSFWorkbook();
            FileInputStream stream = new FileInputStream("c:\\temp\\test.xls");
            wb.write(stream);
            stream.close();
           }catch(IOException e) {
            e.printStackTrace();
    }but then I also made sure I could create a new text file to the same path (works fine). In other words, I can perform my file operations as expected, but I don't undertand what is happening to my HSSFWorkbook object, since it should already have it's own method "write".
    Thanks.
    Edited by: haroldopaulino on Feb 2, 2010 11:42 AM

    You write to an OutputStream, you read from an InputStream.
    And this topic has nothing to do with Swing, which is the subject of this forum. I'm moving it.
    db

  • Copy and Paste from an excel spreadsheet to a JTable

    Hi,
    does someone know how to copy and paste data from an excel spreadsheet to a JTable. It seems like copy and paste do not fuction from an to a JTable.
    Thanks, Fred.

    Take a look at an example included in my bug report link shown below:
    http://developer.java.sun.com/developer/bugParade/bugs/4748394.html
    ;o)
    V.V.

  • Export JTable Column headers to Excel document

    Hello all!!! I am having a small problem while trying to export some data from a jTable to an excel document.
    I have a jTable and I use a custom TableModel with this:
    private String[] columnNames = {"First", "Second", "Third", "Forth"};as names for each column of the table.
    The thing I am trying to do is to export exactly the same "headers" from the columns of the jTable to the excel spreadsheet using Jakarta POI. Unfortunately I don't know how to do it and I haven't found anything yet on this forum. Can anyone help me with this?
    In simple words I want to know how I can have the same headers from my jTable columns, with the headers from the excel doument I will create.
    Many thanks in advanve!!!
    Kostas

    Thank you for your reply first of all. The problem is how to get the heading text and how to put it to the excel's first row OR to excels "headings" (if it is possible...). [in other words replace A,B,C,D from the excel document with the headers I get from the jTable...] .
    I hope now you can see what I am looking for... If there is no solution to this please tell me what are the alternatives. (B) could be a good example.
    Thanks you very much!!
    Kostas

  • Implementing frozen rows/columns in a JTable layout like MS Excel

    I am trying to develop a complex application in which I have a JTable defined, the column names are Name, Admin status , slot id , ipaddress
    as per the query to the database this JTable is populated with the data, now I have a button called freeze pane on this panel (let say it admin panel) , I need to implement a feature where if I select a row from JTable and click on the freeze pane button then all the rows above this selected row should be locked , and when I do scrolling only the rows below this selected row should scroll, the upper rows should be fix, this implementation is similar to that of feature " freeze pane " in microsoft excel. Kindly let me know if it's possible and if yes can you provide me with a sample of code.
    Thanx in advance.

    Even I was searching for some help on implementing the freeze/unfreeze functionality in the JTable. If you have come across any solution, pls provide me with the approach.

  • Export data form JTable to excel

    Hi! i want to export data from JTable to excel.
    could you help me please?

    Despite your question looks doesn't seems to be very complex, I feel pity I am a newbie can not offer you the answers. I am more familiar with exporting data to excel in C#. I've worked with a Data Grid control, just like the JTable. Here are some C# code example. Maybe you can take them as a kind of reference.
    ExportToExcelML exporter = new ExportToExcelML(this.ketticGridView1);
    exporter.HiddenColumnOption = Kettic.WinForm.UI.Export.HiddenOption.DoNotExport;
    exporter.ExportVisualSettings = true;
    exporter.SheetMaxRows = ExcelMaxRows._1048576;
    exporter.SheetName = "NewSheet";
    exporter.SummariesExportOption = SummariesOption.DoNotExport;
    string fileName = "C:\\ExportedGridData1.xls";
    exporter.RunExport(fileName);

  • 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

  • Copy the contents of Jtabl with line breaks to Excel

    Hi every one,
    In my stand alone application,I am copying the contents of Jtable i.e contents having the line breaks(\n).
    While copying and pasting the contents to Jtable,instead of linebreaks, a square symbol is appearing in the excel along with the line break.line break functionality is happening,but the additional symbol(empty square box) is appearing.
    here is my code:
    S = (String) "\""+mProcessQuestionTestItemTable.getValueAt(rowsselected, colsselected[j])+"\""; S=S.replace("\r\n", "\n").replace("\n", "\r\n");
    stringbuffered.append(S);can anyone help me in this?
    thank you!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi,
    I want to copy the contents of Jtable(contents having Line breaks(\n)) and pasting to Excel.
    While pasting the contents to Excel, a box is appearing in the excel.
    To remove the empty square box, i tried the sample code:
    originalstr =(String)"\""+ mProcessQuestionTestItemTable.getValueAt(rowsselected, colsselected[j])+"\"";
    originalstr=originalstr.replace("\r\n", "\n").replace("\n", "\r\n");
    strngBuffere.append(S);
    There will be no box,If i copy the contents of Jtable and pasting in notepad.
    the box is appearing in Excel only.
    can you suggest something to solve this..
    Thank you.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to wrap JTable cell like EXCEL sheet??

    Hi All,
    I am using JTable and i want to wrap cell of that table like excel sheet whtn text length is more .
    i m using jdk 1.4.2 & jre 1.4
    can any body help me on that??
    == gavin

    Search this forum on "wrap text in table cell" I got a ton of hits.
    Cheers
    DB

  • Make JTable like Excel Sheet..... how?

    hi
    I am tring to make a JTable in my program just like a Excel worksheet that can add values at the end of column some thing like
    |column name|
        10
        10
        10
        10
        40i created a JTabel but the prob is how can i add values form cells from JTable after displaying ,
    Any Idea or other way to do this except JTable
    Regards
    Satinderjit

    hi there
    i wrote some code and my table displays the things i want, it calculate the data i mean add all the data i gave, i want when table dispaled in a contentpane then i edit any cell and the total at end of column will be updated,thats the prob now...
    here is code from my program
    mymodel.addColumn("<html><b><font color=blue><FONT SIZE=4>S.No.</FONT></font></b></html>");
          mymodel.addColumn("<html><b><font color=blue><FONT SIZE=4> Name</FONT></font></b></html>");
          mymodel.addColumn("<html><b><font color=blue><FONT SIZE=4>Cost #1</FONT></font></b></html>");
          mymodel.addColumn("<html><b><font color=blue><FONT SIZE=4>Cost #2</FONT></font></b></html>");
          data[2] = "10";
          data[3] = "0";
          for(int i=1; i <= expence.length; i++)
            data[0] = Integer.toString(i);
            data[1] = expence[i-1];
            mymodel.addRow(data);
          mymodel.setValueAt(Integer.toString(Calculations()),24,2);"expence" is a String[] having some names
    Regards
    Satinderjit

  • To refresh the contents in JTextArea on selection of a row in JTable.

    This is the block of code that i have tried :
    import java.awt.GridBagConstraints;
    import java.awt.SystemColor;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;
    import ui.layouts.ComponentsBox;
    import ui.layouts.GridPanel;
    import ui.layouts.LayoutConstants;
    import util.ui.UIUtil;
    public class ElectronicJournal extends GridPanel {
         private boolean DEBUG = false;
         private boolean ALLOW_COLUMN_SELECTION = false;
    private boolean ALLOW_ROW_SELECTION = true;
         private GridPanel jGPanel = new GridPanel();
         private GridPanel jGPanel1 = new GridPanel();
         private GridPanel jGPanel2 = new GridPanel();
         DefaultTableModel model;
         private JLabel jLblTillNo = UIUtil.getHeaderLabel("TillNo :");
         private JLabel jLblTillNoData = UIUtil.getBodyLabel("TILL123");
         private JLabel jLblData = UIUtil.getBodyLabel("Detailed View");
         private JTextArea textArea = new JTextArea();
         private JScrollPane spTimeEntryView = new JScrollPane();
         private JScrollPane pan = new JScrollPane();
         String html= " Item Description: Price Change \n Old Price: 40.00 \n New Price: 50.00 \n Authorized By:USER1123 \n";
         private JButton jBtnExporttoExcel = UIUtil.getButton(85,
                   "Export to Excel - F2", "");
         final String[] colHeads = { "Task No", "Data", "User ID", "Date Time",
                   "Description" };
         final Object[][] data = {
                   { "1", "50.00", "USER123", "12/10/2006 05:30", "Price Change" },
                   { "2", "100.00", "USER234", "15/10/2006 03:30", "Price Change12345"},
         final String[] colHeads1 = {"Detailed View" };
         final Object[][] data1 = {
                   { "Task:Price Change", "\n"," Old Price:50.00"," \n ","New Price:100.00"," \n" }
         JTable jtblTimeEntry = new JTable(data, colHeads);
         JTable jTbl1 = new JTable(data1,colHeads1);
         ComponentsBox jpBoxButton = new ComponentsBox(LayoutConstants.X_AXIS);
         public ElectronicJournal() {
              super();
              jtblTimeEntry.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              if (ALLOW_ROW_SELECTION) { // true by default
    ListSelectionModel rowSM = jtblTimeEntry.getSelectionModel();
    rowSM.addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
    //Ignore extra messages.
    if (e.getValueIsAdjusting()) return;
    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
    if (lsm.isSelectionEmpty()) {
    System.out.println("No rows are selected.");
    } else {
    int selectedRow = lsm.getMinSelectionIndex();
    System.out.println("Row " + selectedRow
    + " is now selected.");
    textArea.append("asd \n 123 \n");
    } else {
         jtblTimeEntry.setRowSelectionAllowed(false);
              if (DEBUG) {
                   jtblTimeEntry.addMouseListener(new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
         printDebugData(jtblTimeEntry);
              initialize();
         private void printDebugData(JTable table) {
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    System.out.println("Value of data: ");
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + model.getValueAt(i, j));
    System.out.println();
    System.out.println("--------------------------");
         private void initialize() {
              this.setSize(680, 200);
              this.setBackground(java.awt.SystemColor.control);
              jBtnExporttoExcel.setBackground(SystemColor.control);
              ComponentsBox cmpRibbonHORZ = new ComponentsBox(LayoutConstants.X_AXIS);
              cmpRibbonHORZ.addComponent(jBtnExporttoExcel, false);
              jpBoxButton.add(cmpRibbonHORZ);
              this.addFilledComponent(jGPanel, 1, 1, 1, 1, GridBagConstraints.BOTH);
              this.addFilledComponent(jGPanel1, 2, 1, 11, 5, GridBagConstraints.BOTH);
              this.addFilledComponent(jGPanel2, 2, 13, 17, 5, GridBagConstraints.BOTH);
              jGPanel.setSize(650, 91);
              jGPanel.setBackground(SystemColor.control);
              jGPanel.addFilledComponent(jLblTillNo,1,1,GridBagConstraints.WEST);
              jGPanel.addFilledComponent(jLblTillNoData,1,10,GridBagConstraints.BOTH);
              jGPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0));
              jGPanel1.setBackground(SystemColor.control);
              jGPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0,
                        0));
              spTimeEntryView.setViewportView(jtblTimeEntry);
              jGPanel1.addFilledComponent(spTimeEntryView, 1, 1, 11, 4,
                        GridBagConstraints.BOTH);
              jGPanel2.addFilledComponent(jLblData,1,1,GridBagConstraints.WEST);
              jGPanel2.setBackground(SystemColor.control);
              jGPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0,
                        0));
              //textArea.setText(html);
              pan.setViewportView(textArea);
         int selectedRow = jTbl1.getSelectedRow();
              System.out.println("selectedRow ::" +selectedRow);
              int colCount = jTbl1.getColumnCount();
              System.out.println("colCount ::" +colCount);
              StringBuffer buf = new StringBuffer();
              System.out.println("Out Of For");
              /*for(int count =0;count<colCount;count++)
              {System.out.println("Inside For");
              buf.append(jTbl1.getValueAt(selectedRow,count));
              // method 1 : Constructs a new text area with the specified text. 
              textArea  =new JTextArea(buf.toString());
              //method 2 :To Append the given string to the text area's current text.   
             textArea.append(buf.toString());
              jGPanel2.addFilledComponent(pan,2,1,5,5,GridBagConstraints.BOTH);
              this.addAnchoredComponent(jpBoxButton, 7, 5, 11, 5,
                        GridBagConstraints.CENTER);
    This code displays the same data on the JTextArea everytime i select each row,but my requirement is ,it has to refresh and display different datas in the JTextArea accordingly,as i select each row.Please help.Its urgent.
    Message was edited by: Samyuktha
    Samyuktha

    Please help.Its urgentThen why didn't you use the formatting tags to make it easier for use to read the code?
    Because of the above I didn't take a close look at your code, but i would suggest you should be using a ListSelectionListener to be notified when a row is selected, then you just populate the text area.

  • Changing the size of column in JTable as per requirement

    I'm copying content of excel file into the JTable.
    But as the number of columns increases the size of columns get reduced.
    But i want the table of same column size for any number of columns in the table.
    If display area size is less then JTable must scroll according to the size.

    Scroll bars appear when the table's size is larger than the scrollpane's viewport. So your viewport is a fixed size. You adjust the size of the table to get the scrollbars to appear and get smaller (as the table's size increases).

  • JTable - Help with column names and rowselection

    Hi,
    Is there anyone that can help me. I have successfully been able to load a JTable from an MS access database using vectors. I am now trying to find out how to hardcode the column names into the JTable as a string.
    Can anyone please also show me some code on how to be able update a value in a cell (from ''N'' to ''Y'') by double clicking on that row.
    How can I make all the other columns non-editable.
    Here is my code:
         private JTable getJTable() {
              Vector columnNames = new Vector();
    Vector data = new Vector();
    try
    // Connect to the Database
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    // String url = "jdbc:odbc:Teenergy"; // if using ODBC Data Source name
    String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Documents " +
              "and Settings/Administrator/My Documents/mdbTEST.mdb";
    String userid = "";
    String password = "";
    Class.forName( driver );
    Connection connection = DriverManager.getConnection( url, userid, password );
    // Read data from a table
    String sql = "select * from PurchaseOrderView";
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery( sql );
    ResultSetMetaData md = rs.getMetaData();
    int columns = md.getColumnCount();
    // Get column names
    for (int i = 1; i <= columns; i++)
    columnNames.addElement( md.getColumnName(i) );
    // Get row data
    while (rs.next())
    Vector row = new Vector(columns);
    for (int i = 1; i <= columns; i++)
    row.addElement( rs.getObject(i) );
    data.addElement( row );
    rs.close();
    stmt.close();
    catch(Exception e)
    System.out.println( e );
              if (jTable == null) {
                   jTable = new JTable(data, columnNames);
                   jTable.setAutoCreateColumnsFromModel(false);
                   jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_NEXT_COLUMN);
                   jTable.setShowHorizontalLines(false);
                   jTable.setGridColor(java.awt.SystemColor.control);
                   jTable.setRowSelectionAllowed(true);
                   jTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
                   jTable.setShowGrid(true);     
              return jTable;
         }

    this method has a default behavior to supply exactly what you're seeing: column names consisting of the capitalized letters, "A", "B", "C".Thanks Pete, had seen that but never really thought about it... about 10 days ago somebody needed to obtain Excel column names, I'd offered a rigorous solution and now see it would have been shorter and simpler (if a little heavier) to extend DefaultTableModel and provide the two additional methods needed (getOffsetCol and getColIndex).
    Not much of a difference in LOC but certainly more elegant ;-)
    Darryl

  • Opening an excel file in Acton Performed of jbutton

    Hi,
    In my code I have created a Jtable. i have "An export to excel" Button through which i can export the table to an excel. Is there any way so that when i click the button right way the excel opens.I have attatched a sample of my code. please help.
    public void exportTable() {
            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 ");
                        for(int j=0; j<columnNames.length; j=j+1) {
                            columnNames[j]=table.getColumnModel().getColumn(j).getHeaderValue().toString();
                            data=columnNames[j];
                            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);
                        JOptionPane.showMessageDialog(null,"File Exported Successfully. File Name :"+filename,"WorkLoad Table",JOptionPane.INFORMATION_MESSAGE);
                    }catch(Exception e) {
                        JOptionPane.showMessageDialog(null, "Error "+e);
            } catch (Exception E) {
                System.out.println("Error While Exporting Table "+E);
        }//export TableThis method is called in the Action performed method of "Export to excel" J Button.

    Hi
    To open an OS specific application to open a file use Desktop class.
    Desktop.getDesktop().open(File file);i'm getting some strange problem in this, but try if it works for you.
    --Azodious_                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to convert an output retrieved from database to an excel sheet?

    Hello friends,
    I am preparing an online JSP based project for our training and placement department.
    In this context, I am showing an output into a JTable format to the user for the shortlisted candidates by retrieving this information from my database (MySQL).
    Now I need to convert this output into the Excel Sheet so that I can perform various operations over there.
    So, what are the things required to perform from my side for implementing the same.

    The easiest thing for you to do would be to save it as CSV (Comma Separated Values). In general, your fields would be separated by commas, and any fields that are not numbers would be surrounded with double quotes:
    1,"text",...
    Dates and times are semi-tricky, but excel is pretty good about accepting "YYYY/MM/DD" and "HH:MI AM" format.
    Other than that, you'll be learning the internal structures of Excel or perhaps there is a third-party library that can do this for you...

Maybe you are looking for

  • Install drive error

    Acrobat X installer (from DVD) apparently has a default drive which probably cannot be a network share.  I am trying to install and it kicks back an error concerning my H: drive which  is my network share.  How can I get it to install on C: or D:? Th

  • External Hard Drive Does Not Show Up Anymore

    I got this Western Digital hard drive since last year, and been storing a lot of information on it , some of those, are very important. The HD works smoothly, and fast. But last week I was moving multiple files the same time (my HD is used to that),

  • PDF output does not match Frame TOC

    My Frame TOC is accurate, the tags are correct.  My PDF output has the correct Units in place.  However, in the PDF TOC on the left nav,  the Unit 5 Lessons appear in Unit 4, the Unit 6 Lessons appear in Unit 5, Unit 6 has no Lessons, Unit 7 is corre

  • HT4859 Can I get back to start up assistant after I have set up phone originally

    can I get back to start up assistant after Iphone 4 S set up in shop yesterday? Have notes backed up in icloud from old phone and don't know how to get them onto new phone?

  • How to change the battery in my bluetooth

    i got the new one but don't want to harm the case to change it.a little help please.