|
이건우 님이 쓰신 글 :
: 스트링그리드 데이타를 .csv로 저장해서 엑셀로 여는 방법좀 알려주세요 ㅠㅠ
: 고수님들 부탁 드립니다
대단히 간단한데요
(Col구분은 ','로 하고 Row는 "\r\n")
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
AnsiString sContents;
for(int iRow=0;iRow<StringGrid1->RowCount;iRow++){
for(int iCol=0;iCol<StringGrid1->ColCount;iCol++){
sContents= sContents+ StringGrid1->Cells[iCol][iRow]+AnsiString(",");
}
sContents= sContents+AnsiString("\r\n");
}
AnsiString sFileName ="C:\\Test.csv";
if(FileExists(sFileName)) {
DeleteFile(sFileName);
}
int iFileHandle=FileCreate(sFileName);
FileWrite(iFileHandle,sContents.c_str(),sContents.Length());
FileClose(iFileHandle);
}
//---------------------------------------------------------------------------
|