Results 1 to 10 of 10

Thread: ms excel

  1. #1
    cool_gal is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Exclamation ms excel

    Does anybody know the code to copy data(string) from system clipboard to an ms-excel workbook. (s'pose the data is in the clipboard)

    plz reply asap, its urgent

  2. #2
    taqi10 is offline Member
    Join Date
    Jul 2007
    Posts
    1
    Rep Power
    0

    Default

    getting data from System Clipboard is not difficult you can easily get data from System Clipboard and store it in a string type variable but the problem is that how will you transfer that string or write that string to the Excel, one possible solution to transfer the data to the Excel is to use teh JExcel API, search google for JExcel API,with this API you can write data or read from excel files, as far as the code for getting data from clipboard is concerened I am pasting it as below:

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.awt.datatransfer.*;
    
    public class ClipTest1 extends Component  implements ClipboardOwner
    {
    	public static void main(String [] args)
    	{
    		ClipTest1 obj =new ClipTest1();
    		obj.testMethod();
    	}
    
    	public void testMethod()
    	{
    		try
    		{
    			Clipboard clipboard;
    			clipboard = getToolkit().getSystemClipboard();
    			Transferable clipboardContent = clipboard.getContents (this);
    			String tempString;
    			tempString = (String) clipboardContent.getTransferData (DataFlavor.stringFlavor);
    			System.out.println(tempString);
    		}
    
    		catch(Exception en)
    		{
    			System.out.println(en);
    		}
    	}
    
    	public void lostOwnership (Clipboard parClipboard, Transferable parTransferable)
    	{
    	 	  System.out.println ("Lost ownership");
    	}
    
    
    
    }
    Regards,
    Taqi Raza.
    Last edited by JavaBean; 07-12-2007 at 09:20 AM. Reason: Code placed inside [code] tag.

  3. #3
    cool_gal is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Exclamation

    exactly, thts the point, i'm using jxcell api, but say if i have to copy from ms-word to clipboard it gives me weird kinds of boxes, can u help me wid tht?

  4. #4
    cool_gal is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Default

    anybody.... please

  5. #5
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    What do you mean weird kind kinds of boxes and what is your code to copy?

  6. #6
    cool_gal is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Default

    ÿÿ ¤ ¤ ¤ ¤ ¤ ¤ ¤ ¤  ¸     ( ¸ å ¶ @ @ @ @ @ @ @ @ d  f f f f f f $ › h  b Š  ¤

    weird characters like this, try opening word file wid notepad, u'll see small boxes

    my code basically opens 2 files(one doc n other xls) as bufferedreader n bufferedwriter respectivel, n using readLine i read from doc n write() to xls

    String s1="C:\\"+ft.getText()+".txt"; //Address of the doc file
    String s2="C:\\"+ft.getText()+".xls";
    BufferedReader fileIn = new BufferedReader(new FileReader(s1));

    View view = new View();
    String line;

    while((line=fileIn.readLine())!=null)
    {
    view.setEntry(i,0,line);
    i++;
    view.write(s2,View.eFileExcel);

  7. #7
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    But word documents are binary documents. They have a binary structure. You can not read them line by line. This is why you get those symbols. You should use a library to read word documents appropriately.

  8. #8
    cool_gal is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Default

    can u suggest one?

  9. #9
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

  10. #10
    liqdok is offline Member
    Join Date
    Jul 2007
    Posts
    6
    Rep Power
    0

Similar Threads

  1. JSP To EXCEL
    By sureshsri1981 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 09-24-2009, 11:12 PM
  2. jsp excel
    By lak in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 11:53 AM
  3. export to excel
    By diana glz in forum Advanced Java
    Replies: 0
    Last Post: 03-14-2008, 12:01 AM
  4. export to excel
    By diana glz in forum New To Java
    Replies: 0
    Last Post: 03-13-2008, 10:26 PM
  5. Javascript into Excel
    By gdj100 in forum Advanced Java
    Replies: 0
    Last Post: 03-12-2008, 12:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •