본문 바로가기
WORK/Sotfware

볼란드 excel 제어

by KANG Stroy 2009. 8. 25.
728x90
728x90
아래의 코드는 엑셀 프로그램을 열지 않고 직접 엑셀 파일로 저장하는 코드입니다.
유용하게 사용하세요.

WORD CXlsBof[6] = {0x809, 8, 0, 0x10, 0, 0};
WORD CXlsEof[2] = {0x0A, 0};
WORD CXlsLabel[6] = {0x204, 0, 0, 0, 0, 0};
WORD CXlsNumber[5] = {0x203, 14, 0, 0, 0};
WORD CXlsRk[5] = {0x27E, 10, 0, 0, 0};


void __fastcall XlsBeginStream(TStream *XlsStream, const WORD BuildNumber)
{
    CXlsBof[4] = BuildNumber;
    XlsStream->WriteBuffer(CXlsBof, sizeof(CXlsBof));
}

void __fastcall XlsEndStream(TStream *XlsStream)
{
    XlsStream->WriteBuffer(CXlsEof, sizeof(CXlsEof));
}

void __fastcall XlsWriteCellRk(TStream *XlsStream, const WORD ACol, const
WORD ARow, const
int AValue)
{
    CXlsRk[2] = ARow;
    CXlsRk[3] = ACol;
    XlsStream->WriteBuffer(CXlsRk, sizeof(CXlsRk));
    int V = ((AValue << 2) | 2);
    XlsStream->WriteBuffer(&V, 4);
}

void __fastcall XlsWriteCellNumber(TStream *XlsStream, const WORD ACol,
const WORD ARow, const double AValue)
{
    CXlsNumber[2] = ARow;
    CXlsNumber[3] = ACol;
    XlsStream->WriteBuffer(CXlsNumber, sizeof(CXlsNumber));
    XlsStream->WriteBuffer(&AValue, 8);
}

void __fastcall XlsWriteCellLabel(TStream *XlsStream, const WORD ACol, const
WORD ARow, const AnsiString AValue)
{
    WORD L = AValue.Length();
    CXlsLabel[1] = 8 + L;
    CXlsLabel[2] = ARow;
    CXlsLabel[3] = ACol;
    CXlsLabel[5] = L;
    XlsStream->WriteBuffer(CXlsLabel, sizeof(CXlsLabel));
    XlsStream->WriteBuffer(AValue.c_str(), L);
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TFileStream *FStream = new TFileStream("c:\\e.xls", fmCreate);
    try
    {
        XlsBeginStream(FStream, 0);
        for(int i = 0; i < 100; i++)
        {
            for(int j = 0; j < 100; j++)
                XlsWriteCellNumber(FStream, i, j, 34.34);
        }
        XlsEndStream(FStream);
    }
    __finally
    {
        delete FStream;
    }
}

[펌] http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=201
728x90

댓글