PDA

View Full Version : آموزش: چگونه داده های انگلیسی یک Grid را در اکسل بریزیم؟



behzadboloori
شنبه 05 تیر 1389, 10:00 صبح
حالت اول: چگونه یک فایل اکسل ایجاد کنیم و درون آن اطلاعات بریزیم.




//declare variables
Variant XL,v0,v1,v2,v3;
double x=3.14;

//open excel application
XL=Variant::CreateObject(”excel.application”);

//set the application as invisible, you can reverse “false” to “true” to make it visible
XL.OlePropertySet(”Visible”,false);

//Get workbook
v0=XL.OlePropertyGet(”Workbooks”);

//add one work book
v0.OleProcedure(”Add”);

//select workbook number 1
v1=v0.OlePropertyGet(”Item”,1);

//Get worksheet
v2=v1.OlePropertyGet(”WorkSheets”);

// add one work sheet
v2.OleFunction(”Add”);

//select worksheet number 1
v3=v2.OlePropertyGet(”Item”,1);

//rename worksheet it to “example1″
v3.OlePropertySet(”Name”,”example1″);

// at last, write your output at row 2 column 3
char temp[10];
sprintf(temp,”%lf”,x);
v3.OlePropertyGet(”Cells”).OlePropertyGet(”I tem”,2,3).OlePropertySet(”Value”,temp);

//this will stop asking you where you want to same your excel file or not
XL.OlePropertySet(”DisplayAlerts”,false);

//save your excel file at “d” and name it as “case1.xls”
XL.OlePropertyGet(”Workbooks”).OlePropertyGet( ”Item”,1).OleProcedure(”SaveAs”,”d:\\cas e1.xls”);

//Close the work book
v1.OleProcedure(”Close”);

//quite the excel application
XL.OleProcedure(”Quit”);

//unassign variable
XL=Unassigned;



حالت دوم: اطلاعات را در یک فایل اکسل موجود بریزیم

case1.xls
“” located at “D:”

double x=3.14;
//declare variables
Variant XL,v0,v1,v2,v3;

//open excel application
XL=Variant::CreateObject(”excel.application”);

//set the application as invisible, you can reverse “false” to “true” to make it visible
XL.OlePropertySet(”Visible”,false);

//open the workbook� “named case1.xls”
XL.OlePropertyGet(”Workbooks”).OleProcedure( Open”,”d:\\case1.xls”);

//open the worksheet “example1″
v0=XL.OlePropertyGet(”Sheets”,”example1″);

//get a cell
v1=v0.OlePropertyGet(”Cells”);

// at last, write your output at row 2 column 3
char temp[10];
sprintf(temp,”%lf”,x);
v1.OlePropertyGet(”Item”,2,3).OlePropertySet( Value”,temp);

//this will stop asking you where you want to same your excel file or not
XL.OlePropertySet(”DisplayAlerts”,false);

//save what you have done
XL.OleProcedure(”Save”);

//quite the excel application
XL.OleProcedure(”Quit”);

//unassign variable
XL=Unassigned;