青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

VC操作Excel時SaveAs另存為時選擇保存時警告處理

如何自動執行將 Excel 工作表保存為 HTML 文件中使用 Visual c + +

http://support.microsoft.com/kb/199691/zh-cn





VC操作Excel,當用SaveAs保存Excel時,如果待保存路徑下已經存在該Excel,則會彈出一個對話框提示你當前路徑下已經存在該Excel,是否替換,下面有三個按鈕:“是”、“否”、“取消”。如果選擇了“取消”則會彈出一個錯誤警告對話框。

可以按照如下方法解決這個問題:在SaveAs之前添加代碼: _Application ExcelApp; ExcelApp.SetAlertBeforeOverwriting(FALSE); ExcelApp.SetDisplayAlerts(FALSE);  

在Office2003版Office所生成的Excel.cpp文件中,類_Workbook的SaveAs函數,其函數原型如下:     void   SaveAs(const   VARIANT&   Filename,       const   VARIANT&   FileFormat,       const   VARIANT&   Password,       const   VARIANT&   WriteResPassword,       const   VARIANT&   ReadOnlyRecommended,       const   VARIANT&   CreateBackup,       long   AccessMode,       const   VARIANT&   ConflictResolution,       const   VARIANT&   AddToMru,       const   VARIANT&   TextCodepage,       const   VARIANT&   TextVisualLayout,       const   VARIANT&   Local);

參數含義參考如下:   Question:       Nothing   like   trying   to   learn/teach   yourself   something   new   to   make   you   humble.   Winbatch   99p,   Excel   97.       I'm   loading   a   tab   delimited   file   {M:\somedir\myfile.txt}   into   Excel   using   OLE   to   manipulate   it   some   &   want   to   save   it   as   an   Excel   .xls   file   {M:\somedir\myfile.txt}.           I   can   get   the   file   to   save   under   the   new   name,   i.e.   with   the   .xls   extension   but   it's   still   in   tab   delimited   format,   NOT   Excel's   native   file   format.   The   following   is   from   a   macro   I   recorded   while   doing   the   action   I   want   to   automate:   ActiveWorkbook.SaveAs   FileName:="M:\TMI_Data\Processed\FEB00.xls",   FileFormat:=xlNormal,   Password:="",   WriteResPassword:="",   ReadOnlyRecommended:=False,   CreateBackup:=False           I   can   get   the   following   code   to   save   the   file   and   add   the   filename   to   the   MRU   list.           fileXL   ="M:\TMI_Data\Processed\FEB00.xls"         Awkbk=ObjXL.ActiveWorkbook       savefile=Awkbk.SaveAs   (fileXL)   ;   this   works           OR       savefile=Awkbk.SaveAs   (   fileXL,   ,   ,   ,   ,   ,@True   )   ;   this   works   the   @True   adds   the   file   to   the   MRU   list.         But,   whenever   I   try   to   insert   something   in   the   position   that   I   think   the   fileformat   stuff   is   supposed   to   go   I   get   1261   OLE   exception   errors   or   3250   OLE   Object   error   :   Problem   occurred   formatting   parameters.   I'm   wondering   if   it's   a   Named   parameter   ?   If   I'm   understanding   the   docs   correctly   (big   IF)   a   named   parameter   would   go   after   all   the   positional   parameters   ?   T/F   ?       I've   tried   a   lot   of   permutations   &   combinations   &   haven't   stumbled   up   on   something   that'll   work   yet.           How   does   one   differentiate   between   /tell   one   from   the   other   on   Named   vice   positional   parameters   ?   I've   looked   in   the   VBA   help   &   haven't   stumbled   onto   anything.           Answer:       Sounds   like   you   almost   have   it.   Positional   parameters   first,   then   the   ::   then   the   parameter=value   pairs   for   the   named   parameters.       Question   (cont'd):       I'm   just   not   grasping   something   here.       I've   tried   the   line   :           savefile=Awkbk.SaveAs   (   fileXL,   ,   ,   ,   ,   ,   ,   ,   ,   ,   ::FileFormat   =   "xlNormal")           with   0   to   10   commas   for   "positional   parameters"   between   the   "fileXL"   &   the   "::".       With   0   or   1   comma   I   get   1261   OLE   exception   Error   &   the   following   entry   from   wwwbatch.ini           [OLE   Exception]     Microsoft   Excel=Unable   to   get   the   SaveAs   property   of   the   Workbook   class         With   2   to   10   commas   I   get   NO   ERRORS,   BUT   while   it   saves   with   an   .xls   extension   it   is   still   Tab   delimited.       How   can   you   tell   if   a   parameter   is   a   "Named   Parameter"   ?           The   VBA   docs   make   the   stuff   all   look   like   "Positional   parameters"           Answer:       Maybe   there   are   three   required   parameters?           Maybe   xlNormal   is   not   a   tring   but   a   constant   and   we   have   to   figure   out   what   number   it   is?           Maybe   cut   and   paste   the   SaveAs   documentation   here   and   we   can   stare   at   it.           Bit   of   an   OLE   tip   that   I   found   a   bit   by   accident.       If   you   want   to   know   whether   something   is   a   string   or   a   constant,   do   it   in   VBA   -   in   this   case,   something   like           var=xlNormal         If   it   bombs   out,   it's   a   string.   If   it   doesn't,   it'll   return   a   value   for   you   to   plug   into   your   scripts.       Here's   the   docs   for   the   "SaveAs   Method"   clipped   direct   from   the   VBA   help   :   Saves   changes   to   the   sheet   (Syntax   1)   or   workbook   (Syntax   2)   in   a   different   file.       Syntax   1       expression.SaveAs(Filename,   FileFormat,   Password,   WriteResPassword,   ReadOnlyRecommended,   CreateBackup,   AddToMru,   TextCodePage,   TextVisualLayout)         Syntax   2     expression.SaveAs(Filename,   FileFormat,   Password,   WriteResPassword,   ReadOnlyRecommended,   CreateBackup,   AccessMode,   ConflictResolution,   AddToMru,   TextCodePage,   TextVisualLayout)         expression   Required.   An   expression   that   returns   a   Chart   or   Worksheet   object   (Syntax   1)   or   a   Workbook   object   (Syntax   2).       Filename   Optional   Variant.   A   string   that   indicates   the   name   of   the   file   to   be   saved.   You   can   include   a   full   path;   if   you   don't,   Microsoft   Excel   saves   the   file   in   the   current   folder.       FileFormat   Optional   Variant.   The   file   format   to   use   when   you   save   the   file.   For   a   list   of   valid   choices,   see   the   FileFormat   property.       Password   Optional   Variant.   A   case-sensitive   string   (no   more   than   15   characters)   that   indicates   the   protection   password   to   be   given   to   the   file.       WriteResPassword   Optional   Variant.   A   string   that   indicates   the   write-reservation   password   for   this   file.   If   a   file   is   saved   with   the   password   and   the   password   isn't   supplied   when   the   file   is   opened,   the   file   is   opened   as   read-only.       ReadOnlyRecommended   Optional   Variant.   True   to   display   a   message   when   the   file   is   opened,   recommending   that   the   file   be   opened   as   read-only.       CreateBackup   Optional   Variant.   True   to   create   a   backup   file.       AccessMode   Optional   Variant.   The   workbook   access   mode.   Can   be   one   of   the   following   XlSaveAsAccessMode   constants:   xlShared   (shared   list),   xlExclusive   (exclusive   mode),   or   xlNoChange   (don't   change   the   access   mode).   If   this   argument   is   omitted,   the   access   mode   isn't   changed.   This   argument   is   ignored   if   you   save   a   shared   list   without   changing   the   file   name.   To   change   the   access   mode,   use   the   ExclusiveAccess   method.       ConflictResolution   Optional   Variant.   Specifies   the   way   change   conflicts   are   resolved   if   the   workbook   is   a   shared   list.   Can   be   one   of   the   following   XlSaveConflictResolution   constants:   xlUserResolution   (display   the   conflict-resolution   dialog   box),   xlLocalSessionChanges   (automatically   accept   the   local   user's   changes),   or   xlOtherSessionChanges   (accept   other   changes   instead   of   the   local   user's   changes).   If   this   argument   is   omitted,   the   conflict-resolution   dialog   box   is   displayed.       AddToMru   Optional   Variant.   True   to   add   this   workbook   to   the   list   of   recently   used   files.   The   default   value   is   False.       TextCodePage   Optional   Variant.   Not   used   in   U.S.   English   Microsoft   Excel.       TextVisualLayout   Optional   Variant.   Not   used   in   U.S.   English   Microsoft   Excel.           Resolution:       GREAT   Tip   --   I   inserted   your   line   into   the   macro   &   then   stepped   thru   it.   It   returned   a   value   of   -4143.   I   plugged   it   into   the   command   like   so:       savefile=Awkbk.SaveAs   (   fileXL,   -4143   ,   ,   ,   ,   ,@True   )         and   SHAZAM   it   works   !   It   would   have   been   A   WHILE   before   I'd   have   stumbled   on   to   that.   Thanks   Again.

參考鏈接: http://topic.csdn.net/t/20050121/15/3743958.html http://topic.csdn.net/t/20050324/11/3876932.html




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
本人參考網上做法,利用模板實現了VC對EXCEL的操作,但是存在以下問題:

  1.第一次運行程序,點擊保存時沒問題,當第二次運行程序時,會彈出對話框,提示已經存在文件,是否替換(是、否、取消),當點擊“否”的時候會彈出警告對話框,程序中斷;
  2.程序運行后,第一次點擊保存時,不會出錯,接著再次點擊保存時,就會出現警告:無法找到模板......;即程序運行后不能實現多次保存。
  3.程序在關閉后,為何在任務管理器的進程里并沒有結束,即不能實現程序在后臺也關閉。
  以下是源代碼,有勞哪位大俠解惑!不勝感激!
  
  void CTEST::OnConnect()  
{
 // TODO: Add your control notification handler code here
 _Application _app;
  _Workbook _workBook;
 _Worksheet _workSheet;
 Worksheets workSheets;
 Workbooks workBooks;
 Range range;
  _Application ExcelApp;  
 ExcelApp.SetAlertBeforeOverwriting(FALSE);  
 ExcelApp.SetDisplayAlerts(FALSE);   
// LPDISPATCH lpDisp;
 char path[MAX_PATH];
 //VARIANT _variant_t;
 if (CoInitialize(NULL) != 0)
 {
  AfxMessageBox("初始化COM支持庫失敗!");
  exit(1);
 }  
  if(!_app.CreateDispatch("Excel.Application", NULL))
 {
  MessageBox("創建Excel服務失敗!", "信息提示", MB_OK);
  return ;
 }
 //利用模板建立新文檔
 _app.SetUserControl(true);
  //_app.SetVisible(true);
 CFileDialog fileDlg(false);
 fileDlg.m_ofn.lpstrFilter="Text Files(*.xls)\0ALL Files(*.*)\0*.*\0\0";
 fileDlg.m_ofn.lpstrDefExt="xls";
 GetCurrentDirectory(MAX_PATH,path);
 CString strPath=path;
 CString Path,Name;
 strPath+="\\模板";
  workBooks=_app.GetWorkbooks();
 _workBook=workBooks.Add(_variant_t(strPath));
  workSheets=_workBook.GetWorksheets();
 _workSheet=workSheets.GetItem(COleVariant((short)1));
 range=_workSheet.GetCells();
 range.SetItem(_variant_t((long)1), _variant_t((long)3), _variant_t("寫入數據了"));
 range.SetItem(_variant_t((long)2), _variant_t((long)3), _variant_t("寫入數據了"));
 range.SetItem(_variant_t((long)3), _variant_t((long)3), _variant_t("寫入數據了"));
 range.SetItem(_variant_t((long)4), _variant_t((long)3), _variant_t("寫入數據了"));  
 if(IDOK==fileDlg.DoModal())//這里實現“另存為”對話框
 {
  Path=fileDlg.GetPathName();
 Name=fileDlg.GetFileName();
 //保存數據   
 _workSheet.SaveAs(Path,vtMissing,vtMissing,vtMissing,vtMissing,
  vtMissing,vtMissing,vtMissing,vtMissing,vtMissing);
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 }  
 range.ReleaseDispatch();
 _workSheet.ReleaseDispatch();
 workSheets.ReleaseDispatch();
 _workBook.ReleaseDispatch();
 workSheets.ReleaseDispatch();
 _app.ReleaseDispatch();
  _workBook.Close(vtMissing,COleVariant(Path),vtMissing);
 workBooks.Close();
 _app.Quit();
 CoUninitialize();
}


以上幾個問題已經解決,倒騰了一晚上。

(1)將char path[MAX_PATH];
GetCurrentDirectory(MAX_PATH,path);
 CString strPath=path;定義成全局變量,   

(2)workBook.Close(vtMissing,COleVariant(Path),vtMissing);  

  改成_ COleVariant aver((long)DISP_E_PARAMNOTFOUND, VT_ERROR); workBook.Close(aver,COleVariant(Path),aver);

這樣的話問題就解決了。




posted on 2010-10-15 10:16 wrh 閱讀(6653) 評論(0)  編輯 收藏 引用

導航

<2011年4月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

統計

常用鏈接

留言簿(19)

隨筆檔案

文章檔案

收藏夾

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久久久久久久蜜桃| 久久亚洲一区二区三区四区| 亚洲视频第一页| 亚洲黄色天堂| 在线不卡a资源高清| 国产综合自拍| 激情小说另类小说亚洲欧美| 韩国三级在线一区| 国产一区二区精品久久91| 国产亚洲欧美日韩美女| 国产日韩欧美电影在线观看| 伊人久久大香线蕉av超碰演员| 亚洲高清毛片| 亚洲自拍都市欧美小说| 西瓜成人精品人成网站| 久久精品亚洲精品国产欧美kt∨| 久久久久久久久伊人| 亚洲国产精彩中文乱码av在线播放| 久久精品一本| 亚洲国产精品嫩草影院| 亚洲一级片在线观看| 久久久久国产精品午夜一区| 欧美激情中文字幕一区二区| 国产精品国产三级国产专播品爱网 | 国产一区白浆| 久久国产精品第一页| 久久人人97超碰人人澡爱香蕉| 欧美激情综合色综合啪啪| 国产精品一二三视频| 亚洲欧洲精品一区二区三区 | 中文日韩欧美| 久久青草福利网站| 欧美性感一类影片在线播放 | 久久精品亚洲一区二区| 欧美日韩精品免费观看视频| 国产一级一区二区| 中文一区二区| 亚洲激情另类| 久久五月激情| 国产亚洲一区二区三区| 亚洲视频在线观看| 欧美黄色网络| 久久精品国产99国产精品| 欧美日一区二区在线观看| 亚洲高清视频在线观看| 久久久久久久欧美精品| 亚洲永久在线观看| 国产精品theporn| av不卡在线| 亚洲韩日在线| 欧美不卡一卡二卡免费版| 国产一区91精品张津瑜| 久久国产日韩| 亚洲图片欧洲图片日韩av| 欧美精品一区二区三| 激情一区二区| 久久久久久久999精品视频| 一本色道久久99精品综合| 欧美国产日韩二区| 亚洲精品美女91| 亚洲国产精品999| 欧美aaa级| 亚洲国产高清在线观看视频| 久久综合久色欧美综合狠狠| 久久国产直播| 一区二区三区自拍| 免费黄网站欧美| 老司机午夜精品| 亚洲高清在线| 欧美二区视频| 欧美国产丝袜视频| 日韩视频中文字幕| 日韩视频―中文字幕| 欧美日韩在线大尺度| 亚洲一区二区三区免费视频| 一个人看的www久久| 国产精品欧美激情| 久久成人精品无人区| 欧美1区2区视频| 久久婷婷丁香| 韩日视频一区| 欧美电影免费| 欧美黄色视屏| 亚洲视频在线观看| 亚洲欧美中文日韩v在线观看| 国产目拍亚洲精品99久久精品| 欧美在线免费观看| 久久九九精品99国产精品| 亚洲国产精品va在线观看黑人| 亚洲激情偷拍| 国产精品日韩欧美一区二区三区| 欧美在线网址| 免费成人激情视频| 亚洲图片欧洲图片av| 午夜精品久久久久影视| 精品999在线播放| 亚洲精品国产精品国产自| 欧美午夜在线| 久久午夜精品| 欧美日本成人| 久久手机精品视频| 欧美日韩的一区二区| 欧美一级视频一区二区| 久久天堂国产精品| 亚洲男人影院| 久久综合久久久| 99pao成人国产永久免费视频| 亚洲综合好骚| 亚洲精品视频在线观看网站 | 亚洲永久免费视频| 亚洲美女黄网| 欧美一区二区三区在线看| 亚洲另类自拍| 亚洲欧美自拍偷拍| 一区二区电影免费观看| 久久精品综合一区| 亚洲桃花岛网站| 久久夜色精品国产欧美乱极品| 亚洲男人av电影| 欧美国产精品久久| 欧美呦呦网站| 欧美人成在线视频| 欧美国产精品人人做人人爱| 国产视频一区在线观看| 亚洲区欧美区| 亚洲国产精品va在线看黑人| 久久精品道一区二区三区| 午夜激情一区| 欧美三级视频在线播放| 亚洲国产综合91精品麻豆| 在线看片成人| 久久av一区二区三区| 亚洲欧美第一页| 欧美色综合天天久久综合精品| 91久久精品美女高潮| 亚洲人成网站影音先锋播放| 久久精品论坛| 久久综合九色99| 精品电影一区| 久久精品卡一| 亚洲福利视频专区| 亚洲精品视频在线观看免费| 亚洲第一久久影院| 欧美日韩亚洲一区在线观看| 91久久久亚洲精品| 99精品国产福利在线观看免费| 久久人人97超碰精品888| 久久影视三级福利片| 国产在线精品成人一区二区三区 | 亚洲高清不卡在线观看| 久久在线播放| 亚洲激情电影中文字幕| 中文亚洲免费| 国产日本精品| 欧美中文字幕视频| 男女激情视频一区| 亚洲经典在线| 欧美日韩视频一区二区三区| 亚洲乱码国产乱码精品精可以看| 一区二区三区四区国产精品| 欧美日韩免费区域视频在线观看| 91久久夜色精品国产九色| 夜夜嗨av一区二区三区中文字幕| 欧美精品国产一区| 亚洲午夜高清视频| 老司机午夜精品| 99热免费精品| 国产午夜精品在线| 欧美不卡高清| 亚洲免费观看视频| 欧美在线视频一区二区| 亚洲国产精品www| 欧美视频二区36p| 亚洲永久免费精品| 蜜桃av一区二区在线观看| 一本色道**综合亚洲精品蜜桃冫 | 欧美天堂亚洲电影院在线播放| 亚洲男人影院| 欧美激情亚洲激情| 亚洲欧美一区二区精品久久久| 影院欧美亚洲| 欧美日韩在线不卡一区| 久久噜噜亚洲综合| 9i看片成人免费高清| 久久久噜噜噜久久| 在线视频欧美日韩精品| 国产一区视频网站| 欧美午夜不卡| 欧美aⅴ一区二区三区视频| 亚洲影院色无极综合| 蜜桃久久精品乱码一区二区| 亚洲精品日本| 国产婷婷色综合av蜜臀av| 欧美激情亚洲视频| 欧美在线一二三区| 在线亚洲一区观看| 免费亚洲电影| 久久精品免费看| 亚洲免费小视频| 亚洲伦理在线免费看|