Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Accessing Excel Cells from Visual C++

Accessing Excel Cells from Visual C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestionlearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Havoc
    wrote on last edited by
    #1

    I am just learning VC++. I am trying to read from an Excel file using VC++ but I can't find any good help on how to do it. Does anyone have any ideas? :confused: :confused:

    R 1 Reply Last reply
    0
    • H Havoc

      I am just learning VC++. I am trying to read from an Excel file using VC++ but I can't find any good help on how to do it. Does anyone have any ideas? :confused: :confused:

      R Offline
      R Offline
      Richard Ellis
      wrote on last edited by
      #2

      G'Day Havoc, You should be able to find enough information in MSDN to get you going. Here is one link to a few articles http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno97ta/html/msoautovc.asp failing that try searching with the key words 'excel' and 'autmation' Good luck Richard.

      W 1 Reply Last reply
      0
      • R Richard Ellis

        G'Day Havoc, You should be able to find enough information in MSDN to get you going. Here is one link to a few articles http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno97ta/html/msoautovc.asp failing that try searching with the key words 'excel' and 'autmation' Good luck Richard.

        W Offline
        W Offline
        wangyiming
        wrote on last edited by
        #3

        #ifndef _EXCELSPACE_H #define _EXCELSPACE_H #include "excel9.h" class CExcelSpace : public CObject { public: CExcelSpace(); ~CExcelSpace(); BOOL OpenExcel(LPCTSTR lpszFileName,LPCTSTR lpszSheetName, BOOL m_bReadOnly = TRUE, BOOL bNewFile = FALSE, BOOL bNewSheet = FALSE ); void Close(); void GetRowColCount(int &row, int &col); COleVariant GetCellValue(int row, int col); BOOL SetCellValue(int row, int col,COleVariant var); BOOL DeleteRow(int row); CString GetFileName() { return m_szFileName; }; BOOL IsReadOnly() { return m_bReadOnly; }; void PrepareFetchData(); void EndFetchData(); BOOL ActiveSheet(LPCTSTR lpszSheetName); BOOL IsSheetExist(LPCTSTR lpszSheetName); BOOL DeleteSheet(LPCTSTR lpszSheetName); BOOL NewSheet(LPCTSTR lpszSheetName); _Application GetApplication() { return excelApp; } protected: CString m_szFileName; CString m_szSheetName; BOOL m_bNewFile; BOOL m_bReadOnly; BOOL m_bValidate; BOOL m_bServiceStarted; BOOL bPreparedFectch; CStringArray fldNames; _Application excelApp; int rowCount, colCount; int curRow; COleSafeArray sa; BOOL StartExcelService(); CString InnerGetColumnName(int col); CString GetCellName(int row, int col); int NameToIndex(LPCTSTR lpszFldName); // Dataset function public: int GetRecordCount() { return rowCount; }; int GetColCount() { return colCount; }; BOOL AddColumn(LPCTSTR lpszColName, int nColType); CString GetColumnName(int col); int GetColumnType(int col); BOOL Delete(); BOOL InsertRow(BOOL bAppend); BOOL Update(); COleVariant GetFieldValue(int col); COleVariant GetFieldValue(LPCTSTR lpszFldName); void SetFieldValue(int col,COleVariant var); void SetFieldValue(LPCTSTR lpszFldname,COleVariant var); BOOL MoveFirst(); BOOL MoveNext(); BOOL MoveBefore(); BOOL IsEOF(); BOOL IsBOF(); public: static BOOL NewExcelSheet(LPCTSTR lpszFilename, LPCTSTR lpszSheetName); static BOOL IsSheetExist(LPCTSTR lpszFilename, LPCTSTR lpszSheetName); static BOOL DeleteSheet(LPCTSTR lpszFilename, LPCTSTR lpszSheetName); static CString OleVariantToStr( const COleVariant & Var); }; #endif ------------------------------------- CExcelSpace::CExcelSpace() { m_szFileName = ""; m_bReadOnly = TRUE; m_bValidate = FALSE; bPreparedFectch = FALSE; curRow = -1; rowCount = colCount = 0; m_bServiceStarted = FALSE; } CExcelSpace::~CExcelSpace() { fldNames.RemoveAll(); Close(); } void CExcelSpac

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups