Is it possible to write into an Excel spreadsheet?

This is a discussion on Is it possible to write into an Excel spreadsheet? within the C++ Programming forums, part of the General Programming Boards category; What I want to do is to read through a word document or text file and copy over certain sentences ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    3

    Is it possible to write into an Excel spreadsheet?

    What I want to do is to read through a word document or text file and copy over certain sentences or phrases into an Excel spreadsheet. I dont know if that is possible with C or C++ but i wanted to ask because I am most comfortable using those languages.

    If it is possible, can anyone give me some pointers on how I would go about doing so? And if it is not, does anyone know of any languages that can perform those actions?

    thanks

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    It IS possible...

    But I don't think it's easy. Look-up COM (Microsoft Component Object Model). As I understand it, this is how something can be copied between Word and Excel. (COM has been around awhile... they may be using something different now.)

  3. #3
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    this is a program used to open Excel SYLK files:
    http://www.smempire.org/projects/SYLK-Pad/
    It is written in VB tho

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    3
    hrm... I am not that great with VB but thanks anyways.


    What exactly is COM and how will it help me write this program? I did a search for COM but the finding didnt provide me with much help.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Talking Heck, I dunno know EXACTLY what COM is!

    I've never used it, I've just read about it... It is an advanced topic, and it's usually going to be used with Windows programs. If you search Amazon.com for "COM Programming", you'll get some hits, but I'd want to actually see to book first.

    I don't know if the definition from FOLDEC will help. It says that COM has evolved into DCOM... So, you might want to search for some DCOM info.

    Here's a link to a site with more COM links.

    I'm not even sure that COM will do what you want... My understanding is that, for example, it allows you to copy stuff from one Windows application to another via the Windows clipboard (i.e. Copy->Paste). And, with COM, all the fonts & windows stuff gets copied... probably the Excel formulas too.

    I was thinking that COM might be an "easy" way for you.

    A more "direct" approach would be to parse and edit the Excel file. (That's really what you said you wanted to do.)
    At wotsit.org you can find the Excel file spec. I haven't downloaded it, but I have looked at a couple of simpler file format specs (wav and bmp), and even the simple ones give me a headache! And, I had to study some VB code to understand how to make a program read the headers. Once, I learned something from studying a snippet of Pascal code... and I've never studied Pascal...

    BTW - The format at wotsit.org is for Excel 97. I've heard that they "locked-down" the file format with '97. So that Excel 79 can open files created with newer versions of Office.

    [EDIT] - More rambling speculation...
    What I'm trying to say is... If there is a function like ReadCell(File, Row, Column), that function would probably be considered part of COM. It could be included in the WinAPI (windows.h), or maybe there's a special COM library extension.

    If you have to write the code to parse & edit the file yourself, you're going to be studying the Excel file format for ...oh ...maybe a week, and you will have to write ...oh ...maybe 100 lines of code.

    Either way, you're going to learn a lot!
    Last edited by DougDbug; 08-29-2003 at 06:38 PM.

  6. #6
    Registered User filler_bunny's Avatar
    Join Date
    Feb 2003
    Posts
    87
    Does it have to be an excel workbook? If you are trying to write into an existing spreadsheet then COM is probably your only option. But if all you are trying to do is write a file that can be automatically opened by Excell with data in the appropriate columns, then why don't you write the file out as a CSV file?

    Place a comma after every field and then name the file foo.csv and there you have it, a file that is automatically associated with excel with the data in the appropriate columns.
    Visual C++ .net
    Windows XP profesional

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    3
    I think you are right and that COM is my only option. After playing around with some C# and using COM's, ive figured out how to open up Word Documents and write things into them. And Ive figured out how to open existing spreadsheets and write things into specific columns and rows.

    But the only thing I cant figure out now is how to parse the Word Document using C#. Should i somehow move all the text into a string and then use System.IO and take advantage of fileStream,StreamReader,etc...? Or is there some function in the microsoft.office.interop.word assembly COM thing that will allow me to parse through a word document?

    thanks
    -awfully confused

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with fstream, one variabile for write and read
    By Smjert in forum C++ Programming
    Replies: 3
    Last Post: 02-03-2009, 10:19 PM
  2. Reroute where programs write to
    By willc0de4food in forum C Programming
    Replies: 7
    Last Post: 09-21-2005, 05:48 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Exporting to spreadsheet (excel or other)
    By jpiepgrass in forum C Programming
    Replies: 3
    Last Post: 07-30-2004, 06:44 PM
  5. Q: Simpliest way to use Excel file?
    By cDir in forum Windows Programming
    Replies: 10
    Last Post: 02-01-2002, 03:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21