|
DBGrid의 내용을 엑셀로 저장할려구 하는데여..
지금 델마당에서 구한 기초 샘플로 개념을 잡고 있는데여..소스를 올려보면여..
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant xlApp, xlBooks, xlBook, xlSheets, xlSheet, VRange;
try
{
xlApp = CreateOleObject("excel.Application");
}
catch (Exception &exception)
{
Application->MessageBox("Excel 에러", "에러", MB_OK);
return;
}
if(SaveDialog1->Execute() == false) return;
if(FileExists(SaveDialog1->FileName))
{
Application->MessageBox("파일이 있습니다", "에러", MB_OK);
return;
}
xlApp.OlePropertySet("DisplayAlerts", false);
xlApp.OlePropertySet("Visible", false);
xlBooks = xlApp.OlePropertyGet("Workbooks");
xlBooks.OleProcedure("Add");
xlBook = xlBooks.OlePropertyGet("Item", 1);
xlSheets = xlBook.OlePropertyGet("Worksheets");
xlSheet = xlSheets.OlePropertyGet("Item", 1);
xlSheet.OlePropertySet("Name", String("출력자료") );
VRange = xlSheet.OlePropertyGet("Range", "A3");
VRange.OlePropertySet("Value", "StyleNo");
VRange = xlSheet.OlePropertyGet("Range", "B3");
VRange.OlePropertySet("Value", "Col");
VRange = xlSheet.OlePropertyGet("Range", "C3");
VRange.OlePropertySet("Value", "Siz");
VRange = xlSheet.OlePropertyGet("Range", "D3");
VRange.OlePropertySet("Value", "수량");
VRange = xlSheet.OlePropertyGet("Range", "E3");
VRange.OlePropertySet("Value", "단가");
VRange = xlSheet.OlePropertyGet("Range", "A4");
VRange.OlePropertySet("Value", "ING001");
VRange = xlSheet.OlePropertyGet("Range", "B4");
VRange.OlePropertySet("Value", "BK");
VRange = xlSheet.OlePropertyGet("Range", "C4");
VRange.OlePropertySet("Value", "'44");
VRange = xlSheet.OlePropertyGet("Range", "D4");
VRange.OlePropertySet("Value", 1234);
VRange = xlSheet.OlePropertyGet("Range", "E4");
VRange.OlePropertySet("Value", 2223344);
xlBook.OleProcedure("SaveAs", SaveDialog1->FileName);
xlApp.OleProcedure("Quit");
}
//---------------------------------------------------------------------------
위의 코드에서 궁금한게여..분명 저장은 되는데 엑셀을 띄워서 불러오면 불러오지를 못하거든요.
그리고 세로 방향이 아니라 가로방향으로(A4 기준) 저장이 되야 하거든요..
엑셀을 좀더 정밀하게 제어를 하고 싶거든요..고수님들 도와 주세염..어케 해야 하져..
|