c++ excel

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2009
Posts: 2
Reputation: sophie_kiu is an unknown quantity at this point 
Solved Threads: 0
sophie_kiu sophie_kiu is offline Offline
Newbie Poster

c++ excel

 
0
  #1
Aug 20th, 2009
Question1 :
how to use c++ to read/write excel file without changing it into CSV file?

Question2 :
How to use CSV parser in c++? Are there any examples?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 498
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: c++ excel

 
0
  #2
Aug 20th, 2009
http://support.microsoft.com/kb/216686
SUMMARY:There are several advantages to writing your Automation code in straight C++. First and foremost, you can do exactly what you want. Next, your code will be smaller, faster, and easier to debug. And finally, you won't be dependent on any libraries.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 119
Reputation: marco93 is infamous around these parts marco93 is infamous around these parts marco93 is infamous around these parts 
Solved Threads: 12
marco93 marco93 is offline Offline
Junior Poster

Re: c++ excel

 
0
  #3
Aug 20th, 2009
Originally Posted by adatapost View Post
http://support.microsoft.com/kb/216686
Obsolete (~10 years old)
Use #import instead
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 18
Reputation: rdrast is an unknown quantity at this point 
Solved Threads: 1
rdrast rdrast is online now Online
Newbie Poster

Re: c++ excel

 
0
  #4
Aug 21st, 2009
http://www.microsoft.com/interop/doc...ryFormats.mspx

Covers all office formats from 97 through 2007.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 3
Reputation: dmytro is an unknown quantity at this point 
Solved Threads: 0
dmytro dmytro is offline Offline
Newbie Poster

Re: c++ excel

 
0
  #5
Sep 10th, 2009
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 66
Reputation: Protuberance will become famous soon enough Protuberance will become famous soon enough 
Solved Threads: 14
Protuberance's Avatar
Protuberance Protuberance is offline Offline
Junior Poster in Training

Re: c++ excel

 
0
  #6
Sep 10th, 2009
I have a some class which allows to write in a *.xls (not a *.xlsx) files.
  1. //XLSWriter.h
  2. //---------------------------------------------------------------------------
  3. #ifndef XLS_WRITER_IMPL_H
  4. #define XLS_WRITER_IMPL_H
  5.  
  6. #include <stdio.h>
  7. //---------------------------------------------------------------------------
  8.  
  9. #define CBOF 0x0009
  10. #define BIT_BIFF5 0x0800
  11. #define BOF_BIFF5 (CBOF | BIT_BIFF5)
  12.  
  13. #define BIFF_EOF 0x000A
  14. #define DOCTYPE_XLS 0x0010
  15.  
  16. #define DIMENSIONS 0x0000
  17.  
  18. #define BLANK 0x0000
  19. #define DIM_LEN 0x0008
  20. #define LABEL 0x0004
  21.  
  22.  
  23. class XLSWriter
  24. {
  25. private:
  26. // pointer to a file
  27. FILE* out;
  28. unsigned short blank;
  29. unsigned short bof;
  30. unsigned short tmp;
  31. int iWordSize;
  32. // cell attributes
  33. unsigned char cell_attr[3];
  34. int iMaxRow;
  35. private:
  36. void Blank();
  37. // write into begin of file
  38. void BOF();
  39. void DocTypeXls();
  40. void DIM();
  41. void WriteEOF();
  42. void WriteLabel();
  43. void WriteCellAttr();
  44. public:
  45. // Creating xls file
  46. bool CreateXls(const char* FileName);
  47. // Closing xls file
  48. void CloseXls();
  49. // Writing
  50. void WriteData(const char* Data, int row, int col);
  51. public:
  52. XLSWriter(int MaxRow = 2000); // max number of rows
  53. ~XLSWriter();
  54. };
  55. //---------------------------------------------------------------------------
  56. #endif
  1. //XLSWriter.cpp
  2. //---------------------------------------------------------------------------
  3. #include "stdafx.h"
  4. #include "XLSWriter.h"
  5. #include <string.h>
  6.  
  7. XLSWriter::XLSWriter(int MaxRow)
  8. : out(NULL) ,blank(BLANK) ,bof(BOF_BIFF5) ,iMaxRow(MaxRow) ,tmp(BLANK)
  9. {
  10. iWordSize = sizeof(unsigned short);
  11.  
  12. cell_attr[0] = 0xFF; // default cell attributes
  13. cell_attr[1] = 0xFF;
  14. cell_attr[2] = 0x00;
  15. }
  16.  
  17. XLSWriter::~XLSWriter()
  18. {
  19. if(out)
  20. fclose(out);
  21. }
  22.  
  23. void XLSWriter::Blank()
  24. {
  25. fwrite(&blank,iWordSize,1,out);
  26. }
  27.  
  28. void XLSWriter::BOF()
  29. {
  30. fwrite(&bof,iWordSize,1,out);
  31. tmp = 0x0006;
  32. fwrite(&tmp,iWordSize,1,out);
  33. Blank();
  34. }
  35. //---------------------------------------------------------------------------
  36. void XLSWriter::DocTypeXls()
  37. {
  38. tmp = DOCTYPE_XLS;
  39. fwrite(&tmp,iWordSize,1,out);
  40. Blank();
  41. Blank();
  42. }
  43.  
  44. void XLSWriter::DIM()
  45. {
  46. tmp = DIM_LEN;
  47. fwrite(&tmp,iWordSize,1,out);
  48. Blank();
  49. tmp = (unsigned short) iMaxRow;
  50. fwrite(&tmp,iWordSize,1,out);
  51. Blank();
  52. tmp=10;
  53. fwrite(&tmp,iWordSize,1,out);
  54. }
  55.  
  56. void XLSWriter::WriteEOF()
  57. {
  58. tmp = BIFF_EOF;
  59. fwrite(&tmp,iWordSize,1,out);
  60. Blank();
  61. }
  62.  
  63. void XLSWriter::WriteCellAttr()
  64. {
  65. fwrite(&cell_attr,sizeof(cell_attr),1,out);
  66. }
  67.  
  68. void XLSWriter::WriteLabel()
  69. {
  70. tmp = LABEL;
  71. fwrite(&tmp,iWordSize,1,out);
  72. }
  73.  
  74. bool XLSWriter::CreateXls(const char* FileName)
  75. {
  76. if(!FileName || FileName[0] == 0)
  77. return false;
  78. if(out)
  79. CloseXls();
  80.  
  81. out = fopen(FileName,"wb");
  82. if(!out)
  83. return false;
  84.  
  85. BOF();
  86. DocTypeXls();
  87. DIM();
  88.  
  89. return true;
  90. }
  91.  
  92. void XLSWriter::CloseXls()
  93. {
  94. WriteEOF();
  95. fclose(out);
  96. tmp = BLANK;
  97. }
  98.  
  99. void XLSWriter::WriteData(const char* Data,int row, int col)
  100. {
  101. WriteLabel();
  102. int len = strlen(Data);
  103. tmp = (unsigned short) 8 + len;
  104. fwrite(&tmp,iWordSize,1,out);
  105.  
  106. tmp = (unsigned short) row;
  107. fwrite(&tmp,iWordSize,1,out);
  108. tmp = (unsigned short)col;
  109. fwrite(&tmp,iWordSize,1,out);
  110. WriteCellAttr();
  111. unsigned char btmp = (unsigned char) len;
  112. fwrite(&btmp,1,1,out);
  113. fwrite(Data,btmp,1,out);
  114. }
I am not the author of this class. This class from a free library. I've found it in the google.
"If a problem can be decided - it is not needed to worry, and if to decide it is impossible - worrying is useless." (с)
Reply With Quote Quick reply to this message  
Reply

Tags
excel

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for excel
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC