아래 두 함수를 한번 살표 보세요
ExcelInsertImage
SaveBitmapToExcel
// Variant V;
Variant excel_app;
Variant excel_window;
Variant excel_book;
Variant my_worksheet;
//----------------------------------------------------------------------------
void __fastcall TDLG_RPT_EXCEL::ExcelOpen()
{
excel_app=Variant::CreateObject("excel.application");
excel_app.OlePropertySet("Visible", (Variant)false);
}
//---------------------------------------------------------------------------
void __fastcall TDLG_RPT_EXCEL::ExcelExit()
{
excel_app.OleFunction("Quit");
excel_app = Unassigned;
}
//---------------------------------------------------------------------------
//excel파일을 읽어온다.
void __fastcall TDLG_RPT_EXCEL::ExcelReportFileOpen(AnsiString asFileName)
{
excel_app.OlePropertyGet("WorkBooks").OleProcedure("Open",asFileName.c_str());
excel_window = excel_app.OlePropertyGet("ActiveWindow");
excel_book=excel_app.OlePropertyGet("ActiveWorkbook");
my_worksheet=excel_book.OlePropertyGet("ActiveSheet");
}
//---------------------------------------------------------------------------
// image파일을 특정sheet의 특정 cell에 insert 하는 코드
Variant __fastcall TDLG_RPT_EXCEL::ExcelInsertImage(AnsiString sh_name, int iRow, int iCol, AnsiString iFileName)
{
Variant cells;
my_worksheet = excel_book.OlePropertyGet("WorkSheets", sh_name.c_str());
my_worksheet.OleFunction("Select");
cells = my_worksheet.OlePropertyGet("Cells", iRow, iCol);
cells.OleFunction("Select");
Variant c_image;
c_image = my_worksheet.OlePropertyGet("Pictures").OleFunction("Insert", WideString(iFileName));
c_image.OleFunction("Select");
return c_image;
}
//---------------------------------------------------------------------------
//Bitmap을 특정 Sheet 특정 Cell에 Paste하는 코드
//클립보드를 이용함
void __fastcall TDLG_RPT_EXCEL::SaveBitmapToExcel(Graphics::TBitmap *bmp,String sSheetName,int iRow,int iCol)
{
if(bmp)
{
Clipboard()->Assign(bmp);
my_worksheet = excel_book.OlePropertyGet("WorkSheets", WideString(sSheetName));
my_worksheet.OlePropertyGet("Cells", iRow, iCol).OleProcedure("Select");
my_worksheet.OleProcedure("Paste");
}
}
//---------------------------------------------------------------------------
ExcelInsertImage
SaveBitmapToExcel
// Variant V;
Variant excel_app;
Variant excel_window;
Variant excel_book;
Variant my_worksheet;
//----------------------------------------------------------------------------
void __fastcall TDLG_RPT_EXCEL::ExcelOpen()
{
excel_app=Variant::CreateObject("excel.application");
excel_app.OlePropertySet("Visible", (Variant)false);
}
//---------------------------------------------------------------------------
void __fastcall TDLG_RPT_EXCEL::ExcelExit()
{
excel_app.OleFunction("Quit");
excel_app = Unassigned;
}
//---------------------------------------------------------------------------
//excel파일을 읽어온다.
void __fastcall TDLG_RPT_EXCEL::ExcelReportFileOpen(AnsiString asFileName)
{
excel_app.OlePropertyGet("WorkBooks").OleProcedure("Open",asFileName.c_str());
excel_window = excel_app.OlePropertyGet("ActiveWindow");
excel_book=excel_app.OlePropertyGet("ActiveWorkbook");
my_worksheet=excel_book.OlePropertyGet("ActiveSheet");
}
//---------------------------------------------------------------------------
// image파일을 특정sheet의 특정 cell에 insert 하는 코드
Variant __fastcall TDLG_RPT_EXCEL::ExcelInsertImage(AnsiString sh_name, int iRow, int iCol, AnsiString iFileName)
{
Variant cells;
my_worksheet = excel_book.OlePropertyGet("WorkSheets", sh_name.c_str());
my_worksheet.OleFunction("Select");
cells = my_worksheet.OlePropertyGet("Cells", iRow, iCol);
cells.OleFunction("Select");
Variant c_image;
c_image = my_worksheet.OlePropertyGet("Pictures").OleFunction("Insert", WideString(iFileName));
c_image.OleFunction("Select");
return c_image;
}
//---------------------------------------------------------------------------
//Bitmap을 특정 Sheet 특정 Cell에 Paste하는 코드
//클립보드를 이용함
void __fastcall TDLG_RPT_EXCEL::SaveBitmapToExcel(Graphics::TBitmap *bmp,String sSheetName,int iRow,int iCol)
{
if(bmp)
{
Clipboard()->Assign(bmp);
my_worksheet = excel_book.OlePropertyGet("WorkSheets", WideString(sSheetName));
my_worksheet.OlePropertyGet("Cells", iRow, iCol).OleProcedure("Select");
my_worksheet.OleProcedure("Paste");
}
}
//---------------------------------------------------------------------------
'Borland' 카테고리의 다른 글
Excel 셀에 데이터 넣고 색을 바꾸는 방법 (0) | 2010.01.19 |
---|---|
Excel 설치 여부 확인 (0) | 2010.01.19 |
Excel에서 특정 열의 타입을 지정해주는 방법 (0) | 2010.01.19 |
Excel의 셀 범위를 ClipBoard로 Copy 하기 (0) | 2010.01.19 |
Excel의 Text ClipBoard format (0) | 2010.01.19 |