Visual C++6對於動態連結的語法是不標準的,它必須return父類別,而不是自己這個類別,但是在實作上,return this就可以。
CXlsTable.h
// CXlsTable.h: interface for the CXlsTable class.
#ifndef CXLSTABLE1
#define CXLSTABLE1
#include "XlsFile2.h"
class CXlsTable : public CXlsFile2
{
int m_CellNO;
void idW9();
void idAvg();
void idMedian();
void idMax();
void idMin();
public:
void InitForm();
CXlsFile2* iCellNO(std::vector<Cartridge2>::size_type);
CXlsFile2* iChannel(CString, std::vector<Cartridge2>::size_type );
CXlsFile2* iProb (CString, std::vector<Cartridge2>::size_type );
CXlsFile2* iData (RNA& , std::vector<Cartridge2>::size_type );
CXlsFile2* iChannel(CString );
CXlsFile2* iProb (CString );
CXlsFile2* iData (RNA& );
CXlsFile2* operator->() { return this; };
};
#endif
CXlsTable.cpp
準備表格(畫出表格格線、顏色)
在這裡是每一個表格都會有的動作,表格初始化,將表格的格線和顏色標示上去。若是無格線的table,則將此函數設計成空函數。
void CXlsTable::InitForm()
{
int cell_count = 0;
SelectCell("A1","E3")->SetMergeCells()->SetCellBorder(1, 3);
SelectCell("F1","AM1")->SetMergeCells()->SetCellColor(35)->SetCellBorder(1, 3)->SetFontSize(24)->SetCell(/*Table title...*/);
SelectCell("F2","AM2")->SetMergeCells()->SetCellColor(39)->SetCellBorder(1, 3)->SetFontSize(14)->SetCell("WHITE-9點");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("Cell NO");
//...
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("量測日期");
SelectCell("F3","H3")->SetMergeCells()->SetCellColor(6)->SetCellBorder(1, 3)->SetCell(1);
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("x");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("y");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCellColor(41)->SetCell("L");
SelectCell("I3","K3")->SetMergeCells()->SetCellColor(6)->SetCellBorder(1, 3)->SetCell(2);
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("x");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("y");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCellColor(41)->SetCell("L");
SelectCell("L3","N3")->SetMergeCells()->SetCellColor(6)->SetCellBorder(1, 3)->SetCell(3);
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("x");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("y");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCellColor(41)->SetCell("L");
SelectCell("O3","Q3")->SetMergeCells()->SetCellColor(6)->SetCellBorder(1, 3)->SetCell(4);
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("x");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("y");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCellColor(41)->SetCell("L");
SelectCell("R3","T3")->SetMergeCells()->SetCellColor(6)->SetCellBorder(1, 3)->SetCell(5);
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("x");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("y");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCellColor(41)->SetCell("L");
SelectCell("U3","W3")->SetMergeCells()->SetCellColor(6)->SetCellBorder(1, 3)->SetCell(6);
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("x");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("y");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCellColor(41)->SetCell("L");
SelectCell("X3","Z3")->SetMergeCells()->SetCellColor(6)->SetCellBorder(1, 3)->SetCell(7);
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("x");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("y");
SelectCell((char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCellColor(41)->SetCell("L");
//----------------------------------------------------------
cell_count = 0;
SelectCell("AA3","AC3")->SetMergeCells()->SetCellColor(6)->SetCellBorder(1, 3)->SetCell(8);
SelectCell('A', (char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("x");
SelectCell('A', (char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("y");
SelectCell('A', (char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCellColor(41)->SetCell("L");
SelectCell("AD3","AF3")->SetMergeCells()->SetCellColor(6)->SetCellBorder(1, 3)->SetCell(9);
SelectCell('A', (char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("x");
SelectCell('A', (char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCell("y");
SelectCell('A', (char)('A'+cell_count++), 4)->SetCellBorder(1, 3)->SetCellColor(41)->SetCell("L");
SelectCell('A', (char)('A'+cell_count), 3, 'A', (char)('A'+cell_count), 4)->SetMergeCells()->SetCellColor(40)->SetCellBorder(1, 3)->SetCell("CA210-CH"); cell_count++;
SelectCell('A', (char)('A'+cell_count), 3, 'A', (char)('A'+cell_count), 4)->SetMergeCells()->SetCellColor(40)->SetCellBorder(1, 3)->SetCell("CA210-Probe"); cell_count++;
SelectCell('A', (char)('A'+cell_count), 3, 'A', (char)('A'+cell_count), 4)->SetMergeCells()->SetCellColor(40)->SetCellBorder(1, 3)->SetCell("Avg"); cell_count++;
SelectCell('A', (char)('A'+cell_count), 3, 'A', (char)('A'+cell_count), 4)->SetMergeCells()->SetCellColor(40)->SetCellBorder(1, 3)->SetCell("Median"); cell_count++;
SelectCell('A', (char)('A'+cell_count), 3, 'A', (char)('A'+cell_count), 4)->SetMergeCells()->SetCellColor(40)->SetCellBorder(1, 3)->SetCell("Max"); cell_count++;
SelectCell('A', (char)('A'+cell_count), 3, 'A', (char)('A'+cell_count), 4)->SetMergeCells()->SetCellColor(40)->SetCellBorder(1, 3)->SetCell("Min"); cell_count++;
}
擬操作Excel動作的程式碼
讓程式碼本身,就像是人類用電話告訴操作者如何操作Excel一樣,這一切的一切的設計都是為了這一刻!這一點很重要,在程式語言的設計上,可以達到這一點並且善用的,真的會讓程式碼用起來有一種很爽的感覺。
CXlsFile2* CXlsTable::iData(RNA& vCar)
{
m_vCar = vCar;
if (vCar.HaveSeveral("白","9","","1/4")) idW9();
idAvg();
idMedian();
idMax();
idMin();
SelectSheet(1);
SelectCell("A", 5, "AM", 5+m_CellNO)->SetCellBorder(1, 3)->SetHorztlAlgmet(HA_CENTER); //設定對齊方式
SelectCell("A1","AM1")->AutoFitWidth(); //最適欄寬
SetVisible(true);
// SelectCell("A", 5, "AM", 5+m_CellNO)->Sort("B5",1,"C5",1); //排序
// SelectCell("A1","E3")->InsertImage(CurrentPath, 141, 40); //貼Logo
return this;
}
void CXlsTable::idAvg()
{
SelectSheet(1);
CString strTemp;
strTemp.Format("=SUM(AF%d,AC%d,Z%d,W%d,T%d,Q%d,N%d,K%d,H%d)/9",\ //填公式
5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO);
SelectCell("AI", 5+m_CellNO)->SetCellBorder(1, 3)->SetCell(strTemp); //Avg
}
void CXlsTable::idMedian()
{
SelectSheet(1);
CString strTemp;
strTemp.Format("=T%d", 5+m_CellNO);
SelectCell("AJ", 5+m_CellNO)->SetCellBorder(1, 3)->SetCell(strTemp); //Median
}
void CXlsTable::idMax()
{
SelectSheet(1);
CString strTemp;
strTemp.Format("=MAX(AF%d,AC%d,Z%d,W%d,T%d,Q%d,N%d,K%d,H%d)",\ //填公式
5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO);
SelectCell("AK", 5+m_CellNO)->SetCellBorder(1, 3)->SetCell(strTemp); //Max
}
void CXlsTable::idMin()
{
SelectSheet(1);
CString strTemp;
strTemp.Format("=MIN(AF%d,AC%d,Z%d,W%d,T%d,Q%d,N%d,K%d,H%d)",\ //填公式
5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO, 5+m_CellNO);
SelectCell("AL", 5+m_CellNO)->SetCellBorder(1, 3)->SetCell(strTemp); //Min
}
沒有留言:
張貼留言