| | |
c++ excel
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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.
•
•
Join Date: Apr 2008
Posts: 120
Reputation:
Solved Threads: 12
Obsolete (~10 years old)
Use #import instead
Use #import instead
•
•
Join Date: Apr 2008
Posts: 18
Reputation:
Solved Threads: 1
http://www.microsoft.com/interop/doc...ryFormats.mspx
Covers all office formats from 97 through 2007.
Covers all office formats from 97 through 2007.
I have a some class which allows to write in a *.xls (not a *.xlsx) files.
I am not the author of this class. This class from a free library. I've found it in the google.
cpp Syntax (Toggle Plain Text)
//XLSWriter.h //--------------------------------------------------------------------------- #ifndef XLS_WRITER_IMPL_H #define XLS_WRITER_IMPL_H #include <stdio.h> //--------------------------------------------------------------------------- #define CBOF 0x0009 #define BIT_BIFF5 0x0800 #define BOF_BIFF5 (CBOF | BIT_BIFF5) #define BIFF_EOF 0x000A #define DOCTYPE_XLS 0x0010 #define DIMENSIONS 0x0000 #define BLANK 0x0000 #define DIM_LEN 0x0008 #define LABEL 0x0004 class XLSWriter { private: // pointer to a file FILE* out; unsigned short blank; unsigned short bof; unsigned short tmp; int iWordSize; // cell attributes unsigned char cell_attr[3]; int iMaxRow; private: void Blank(); // write into begin of file void BOF(); void DocTypeXls(); void DIM(); void WriteEOF(); void WriteLabel(); void WriteCellAttr(); public: // Creating xls file bool CreateXls(const char* FileName); // Closing xls file void CloseXls(); // Writing void WriteData(const char* Data, int row, int col); public: XLSWriter(int MaxRow = 2000); // max number of rows ~XLSWriter(); }; //--------------------------------------------------------------------------- #endif
cpp Syntax (Toggle Plain Text)
//XLSWriter.cpp //--------------------------------------------------------------------------- #include "stdafx.h" #include "XLSWriter.h" #include <string.h> XLSWriter::XLSWriter(int MaxRow) : out(NULL) ,blank(BLANK) ,bof(BOF_BIFF5) ,iMaxRow(MaxRow) ,tmp(BLANK) { iWordSize = sizeof(unsigned short); cell_attr[0] = 0xFF; // default cell attributes cell_attr[1] = 0xFF; cell_attr[2] = 0x00; } XLSWriter::~XLSWriter() { if(out) fclose(out); } void XLSWriter::Blank() { fwrite(&blank,iWordSize,1,out); } void XLSWriter::BOF() { fwrite(&bof,iWordSize,1,out); tmp = 0x0006; fwrite(&tmp,iWordSize,1,out); Blank(); } //--------------------------------------------------------------------------- void XLSWriter::DocTypeXls() { tmp = DOCTYPE_XLS; fwrite(&tmp,iWordSize,1,out); Blank(); Blank(); } void XLSWriter::DIM() { tmp = DIM_LEN; fwrite(&tmp,iWordSize,1,out); Blank(); tmp = (unsigned short) iMaxRow; fwrite(&tmp,iWordSize,1,out); Blank(); tmp=10; fwrite(&tmp,iWordSize,1,out); } void XLSWriter::WriteEOF() { tmp = BIFF_EOF; fwrite(&tmp,iWordSize,1,out); Blank(); } void XLSWriter::WriteCellAttr() { fwrite(&cell_attr,sizeof(cell_attr),1,out); } void XLSWriter::WriteLabel() { tmp = LABEL; fwrite(&tmp,iWordSize,1,out); } bool XLSWriter::CreateXls(const char* FileName) { if(!FileName || FileName[0] == 0) return false; if(out) CloseXls(); out = fopen(FileName,"wb"); if(!out) return false; BOF(); DocTypeXls(); DIM(); return true; } void XLSWriter::CloseXls() { WriteEOF(); fclose(out); tmp = BLANK; } void XLSWriter::WriteData(const char* Data,int row, int col) { WriteLabel(); int len = strlen(Data); tmp = (unsigned short) 8 + len; fwrite(&tmp,iWordSize,1,out); tmp = (unsigned short) row; fwrite(&tmp,iWordSize,1,out); tmp = (unsigned short)col; fwrite(&tmp,iWordSize,1,out); WriteCellAttr(); unsigned char btmp = (unsigned char) len; fwrite(&btmp,1,1,out); fwrite(Data,btmp,1,out); }
"If a problem can be decided - it is not needed to worry, and if to decide it is impossible - worrying is useless." (с)
![]() |
Similar Threads
- Excel to Web in Real Time? (ASP)
- How to write files to an Excel application (Visual Basic 4 / 5 / 6)
- grabbing source from excel file (was: please, somebody help me!!!) (Visual Basic 4 / 5 / 6)
- Macros in Excel (Visual Basic 4 / 5 / 6)
- Visual C++ and Excel (C++)
Other Threads in the C++ Forum
- Previous Thread: Insertion Into a Doubly Linked List
- Next Thread: headers problem
Views: 752 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for excel







