943,771 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1760
  • C++ RSS
Aug 20th, 2009
0

c++ excel

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
sophie_kiu is offline Offline
25 posts
since Aug 2009
Aug 20th, 2009
0

Re: c++ excel

http://support.microsoft.com/kb/216686
Quote ...
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.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Aug 20th, 2009
0

Re: c++ excel

Obsolete (~10 years old)
Use #import instead
Reputation Points: -76
Solved Threads: 14
Junior Poster
marco93 is offline Offline
132 posts
since Apr 2008
Aug 21st, 2009
0

Re: c++ excel

http://www.microsoft.com/interop/doc...ryFormats.mspx

Covers all office formats from 97 through 2007.
Reputation Points: 40
Solved Threads: 2
Light Poster
rdrast is offline Offline
30 posts
since Apr 2008
Sep 10th, 2009
0

Re: c++ excel

Reputation Points: 10
Solved Threads: 0
Newbie Poster
dmytro is offline Offline
6 posts
since Apr 2009
Sep 10th, 2009
0

Re: c++ excel

I have a some class which allows to write in a *.xls (not a *.xlsx) files.
cpp Syntax (Toggle Plain Text)
  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
cpp Syntax (Toggle Plain Text)
  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.
Reputation Points: 78
Solved Threads: 17
Junior Poster in Training
Protuberance is offline Offline
88 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Insertion Into a Doubly Linked List
Next Thread in C++ Forum Timeline: headers problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC