colevariant存文本文件(colevariant)
大家好,我是小典,我来为大家解答以上问题。colevariant存文本文件,colevariant很多人还不知道,现在让我们一起来看看吧!
1、本身的功能和函数都不行。要做只能写程序,现成的是MFC+VB做的,如下:
2、#import "G:Program FilesCommon FilesMicrosoft SharedOFFICE11MSO.DLL "
3、#import "G:Program FilesCommon FilesMicrosoft SharedVBAVBA6VBE6EXT.OLB "
4、#import "G:Program FilesMicrosoft OfficeOFFICE11EXCEL.EXE " rename( "RGB ", "ExcelRGB ") rename( "Delete ", "ExcelDelete ") rename( "DialogBox ", "ExcelDialogBox ")
5、void Cexcel_picDlg::OnBnClickedOk()
6、{
7、// insert picture to excel
8、// environment: vc2003, excel2003, windows2003
9、using namespace Excel;
10、_variant_t covOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
11、DWORD dwStartTime = GetTickCount();
12、_ApplicationPtr app;//( "Excel.Application ");
13、HRESULT hr = S_OK;
14、CLSID clsid;
15、CLSIDFromProgID(L "Excel.Application ", &clsid);
16、app.CreateInstance(clsid);
17、WorkbooksPtr books;
18、_WorkbookPtr book;
19、long lcid =LOCALE_USER_DEFAULT;
20、SheetsPtr sheets;
21、app-> get_Workbooks(&books);
22、book = books-> Add(covOptional,lcid/*,&book*/);
23、book-> get_Worksheets(&sheets);
24、IDispatchPtr pDisp;
25、sheets-> get_Item(_variant_t((short)1),&pDisp);
26、_WorksheetPtr sheet(pDisp);
27、RangePtr range = sheet-> GetRange(_variant_t( "A1 "),_variant_t( "A1 "));
28、range-> Value2 = "aaa ";
29、LPCSTR m_Path = _T( "C:\flower8.jpg ");
30、PicturesPtr pics = sheet-> Pictures();
31、pics-> Insert(m_Path,VARIANT_FALSE);
32、app-> put_AskToUpdateLinks(lcid,VARIANT_FALSE);
33、app-> put_AlertBeforeOverwriting(lcid,VARIANT_FALSE);
34、app-> put_UserControl(VARIANT_FALSE);
35、app-> put_DisplayAlerts(0,VARIANT_FALSE);
36、LPCTSTR file_name = _T( "c:\aa.xls ");
37、_variant_t varfilename(file_name);
38、DeleteFile(file_name);
39、HRESULT hrMethod = book-> SaveAs(varfilename,covOptional,covOptional,covOptional,covOptional,covOptional,xlNoChange);
40、book-> put_Saved(0,VARIANT_TRUE);
41、book-> Close(COleVariant(VARIANT_FALSE));
42、books-> Close();
43、app-> Quit();
44、}
本文到此讲解完毕了,希望对大家有帮助。
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时候联系我们修改或删除,多谢。