回覆列表
  • 1 # 使用者8465959556705

    簡單的方法是透過ODBC來實現:具體實現一、 包含Excel檔案操作類標頭檔案#include "CSpreadSheet.h"二、 新建Excel檔案,並寫入預設資料// 新建Excel檔名及路徑,TestSheet為內部表名CSpreadSheet SS("c:\\Test.xls", "TestSheet");CStringArray sampleArray, testRow;SS.BeginTransaction();// 加入標題sampleArray.RemoveAll();sampleArray.Add("姓名");sampleArray.Add("年齡");SS.AddHeaders(sampleArray);// 加入資料CString strName[] = {"徐景周","徐志慧","郭徽","牛英俊","朱小鵬"};CString strAge[] = {"27","23","28","27","26"};for(int i = 0; i < sizeof(strName)/sizeof(CString); i++){sampleArray.RemoveAll();sampleArray.Add(strName[i]);sampleArray.Add(strAge[i]);SS.AddRow(sampleArray);}SS.Commit();三、 讀取Excel檔案資料CSpreadSheet SS("c:\\Test.xls", "TestSheet");CStringArray Rows, Column;//清空列表框m_AccessList.ResetContent();for (int i = 1; i <= SS.GetTotalRows(); i++){// 讀取一行SS.ReadRow(Rows, i);CString strContents = "";for (int j = 1; j <= Rows.GetSize(); j++){if(j == 1)strContents = Rows.GetAt(j-1);elsestrContents = strContents + " --> " + Rows.GetAt(j-1);}m_AccessList.AddString(strContents);}

  • 中秋節和大豐收的關聯?
  • 為什麼現在人情淡薄,好朋友隔一段時間不聯絡,關係就淡了,兄弟姐妹也如此?