excel ole saveas 的问题

华华子 2016-09-01 06:39:57

SetPointer(HourGlass!)
ole_object=create oleobject
li = ole_object.ConnectToNewObject( "excel.application" )
if li<>0 then
messagebox('错误','请安装正确的excel版本!')
DESTROY ole_object
return
end if
ole_object.Workbooks.Open(ls_pathname)
ls_savename="c:\temp.txt"
IF FileExists(ls_savename) then FileDelete(ls_savename)
ole_object.activeworkbook.saveas(ls_savename,3)
ole_object.displayalerts=false
ole_object.quit()
ole_object.DisconnectObject()
DESTROY ole_object
//////////////////////////////////////////////////
上面 saveas 部份电脑执行成功,部份电脑执行不成功。 报如下错,哪位pb达人遇到过,帮忙解决


...全文
1943 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
WorldMobile 2016-09-12
  • 打赏
  • 举报
回复
这个应该是office的版本问题,建议要求客户安装相同的office版本
WMERP 2016-09-04
  • 打赏
  • 举报
回复
ole_object.activeworkbook.saveas(ls_savename,3) 这个3好像EXCEL保存的版本参数,具体是什么版本可以度娘一下。 应该是你保存的版本高于这个电脑本省EXCEL的版本,比如你要在只有EXCEL2003的电脑保存2007格式。
[SQL]将Excel表数据导入SQL Server2005的几种方法归纳 数据库 2010-07-27 11:14:26 阅读201 评论0 字号:大中小 订阅 近日在巨轮着手车间负荷数据处理,反馈回来的数据是保存在Excel文件中的,我必须将其导入SQL Server2005中,供存储过程计算。 由于之前没有将Excel数据导入SQL Server2005的经验,因此摸索着花了一天时间才搞定。下面将网上收集到的几种导入方法做个归纳。 方法一、利用SQL Server2005自带的DTS工具,手工导入: 第一步是点击开始并选择运行并输入CMD然后在命令提示符里输入DTSWIZARD。SQL Server 导入和导出向导的欢迎界面将显示出来,如下图所示:(也可以这样打开该界面:1、登录到 SQL Server Management Studio。2、在 “对象资源管理器 ”中右键单击 “管理 ”,在弹出列表中单击 “导入数据 ”。)   当你点击下一步按钮时,它将进入选择数据源向导界面。用户应该选择数据源为Microsoft Office 12.0 Access Database Engine OLE DB Provider 然后在向导界面中点击属性…按钮,它将弹出数据链接属性界面。在所有标签页中,双击数据源属性值并输入电子数据表的位置,例如“C:\Excel2007\Import\SampleData.xlsx”作为导入数据的数据源的Microsoft Office Excel 2007文件名称和路径。然后双击扩展属性并选择Excel 12.0作为属性值。   到Microsoft Office Excel 2007的连接可以通过点击测试连接按钮来进行测试,如下图所示:   在下一个页面中,数据源需要选为SQL Native Client,因为数据将导入到SQL Server 2005。然后你需要选择数据所要导入的服务器名称,并需要配置合适的验证模式,它之后跟着数据库名称。  在这个例子中,我们将使用windows验证连接到本地SQL Server实例,所使用的数据库将是ImportExcel。   在Specify Table Copy or Query(指定表复制或查询)向导界面中,选择copy data from one or more tables or views(从一个或多个表或视图复制数据)选项,并继续这个向导到下一个界面。   在Select Source Table and Views(选择源表和视图)向导界面中,用户需要在源中选择雇员电子数据表,然后在目标中就可以看到ImportExcel.dbo.Employee了。之后点击Edit Mappings…(编辑匹配…),扫描电子数据表中的可用数据,如果数据类型与SQL Server所建议的不同的话那么指定数据类型。   在Save and Execute Package(保存和执行包)向导界面中,有两个选项叫做Execute Immediately(立即执行)和Save SSIS Package as file system(保存SSIS包为文件系统)。你可以选择任何一个选项然后点击Finish(完成)按钮来运行和结束这个包配置。 方法二、在查询分析器里,直接写 SQL语句: 1、如果是导入数据到现有表,则采用 INSERT INTO 表 SELECT * FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$) 的形式 2、如果是导入数据并新增表,则采用 SELECT * INTO 表 FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$) 的形式。 以上语句是将 EXCEL文件里 SHEET1工作表中所有的列都读进来,如果只想导部分列,可以 INSERT INTO 表 (a1,a2,a3) SELECT a1,a2,a3 FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$) 其实可以将 OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$)当成一个表,例如我就写过这样一个句子: INSERT INTO eval_channel_employee(channel,employee_id) SELECT CASE a.渠道 WHEN 'DIY' THEN 1 WHEN 'RDC' THEN 0 WHEN 'KCM' THEN 2 ELSE 3 END ,b.id FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,'Excel 5.0;HDR=YES;DATABASE=c:\temp\name.xls',sheet1$) AS a,pers_employee b WHERE a.员工编码 =b.code 不管是哪种方式,哪种途径,系统都会默认将第一行上的内容作为字段名。 3、利用C#自己开发数据导入小工具 //连接串 string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" + [EXCEL文件,含路径] + ";"; OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); DataTable dtSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"}); DataSet ds = new DataSet(); //一个EXCEL文件可能有多个工作表,遍历之 foreach( DataRow dr in dtSchema.Rows ) { string table = dr["TABLE_NAME"].ToString(); string strExcel = "SELECT * FROM [" + table + "]"; ds.Tables.Add(table); OleDbDataAdapter myCommand = new OleDbDataAdapter(strExcel,conn); myCommand.Fill(ds,table); } conn.Close(); 这样,读取出来的数据就藏在 DataSet里了。 采用这种方式,数据库所在机器不必装有 EXCEL。 总结: 当Excel表中数据完整时,利用SQL自带的导入工具手工导入比较方便。当数据不完整或数据格式对应不上时,使用导入工具会出错,利用SQL查询语句就更便捷。当结合以上两种方法的优点,利用C#自己开发出数据导入工具是最佳选择。
Table of Contents | Index Programming Excel with VBA and .NET Preface Part I: Learning VBA Chapter 1. Becoming an Excel Programmer Section 1.1. Why Program? Section 1.2. Record and Read Code Section 1.3. Change Recorded Code Section 1.4. Fix Misteakes Section 1.5. Start and Stop Section 1.6. View Results Section 1.7. Where's My Code? Section 1.8. Macros and Security Section 1.9. Write Bug-Free Code Section 1.10. Navigate Samples and Help Section 1.11. What You've Learned Chapter 2. Knowing the Basics Section 2.1. Parts of a Program Section 2.2. Classes and Modules Section 2.3. Procedures Section 2.4. Variables Section 2.5. Conditional Statements Section 2.6. Loops Section 2.7. Expressions Section 2.8. Exceptions Section 2.9. What You've Learned Chapter 3. Tasks in Visual Basic Section 3.1. Types of Tasks Section 3.2. Interact with Users Section 3.3. Do Math Section 3.4. Work with Text Section 3.5. Get Dates and Times Section 3.6. Read and Write Files Section 3.7. Check Results Section 3.8. Find Truth Section 3.9. Compare Bits Section 3.10. Run Other Applications Section 3.11. Control the Compiler Section 3.12. Not Covered Here Section 3.13. What You've Learned Chapter 4. Using Excel Objects Section 4.1. Objects and Their Members Section 4.2. Get Excel Objects Section 4.3. Get Objects from Collections Section 4.4. About Me and the Active Object Section 4.5. Find the Right Object Section 4.6. Common Members Section 4.7. Respond to Events in Excel Section 4.8. The Global Object Section 4.9. The WorksheetFunction Object Section 4.10. What You've Learned Chapter 5. Creating Your Own Objects Section 5.1. Modules Versus Classes Section 5.2. Add Methods Section 5.3. Create Properties Section 5.4. Define Enumerations Section 5.5. Raise Events Section 5.6. Collect Objects Section 5.7. Expose Objects Section 5.8. Destroy Objects Section 5.9. Things You Can't Do Section 5.10. What You've Learned Chapter 6. Writing Code for Use by Others Section 6.1. Types of Applications Section 6.2. The Development Process Section 6.3. Determine Requirements Section 6.4. Design Section 6.5. Implement and Test Section 6.6. Integrate Section 6.7. Test Platforms Section 6.8. Document Section 6.9. Deploy Section 6.10. What You've Learned Section 6.11. Resources Part II: Excel Objects Chapter 7. Controlling Excel Section 7.1. Perform Tasks Section 7.2. Control Excel Options Section 7.3. Get References Section 7.4. Application Members Section 7.5. AutoCorrect Members Section 7.6. AutoRecover Members Section 7.7. ErrorChecking Members Section 7.8. SpellingOptions Members Section 7.9. Window and Windows Members Section 7.10. Pane and Panes Members Chapter 8. Opening, Saving, and Sharing Workbooks Section 8.1. Add, Open, Save, and Close Section 8.2. Share Workbooks Section 8.3. Program with Shared Workbooks Section 8.4. Program with Shared Workspaces Section 8.5. Respond to Actions Section 8.6. Workbook and Workbooks Members Section 8.7. RecentFile and RecentFiles Members Chapter 9. Working with Worksheets and Ranges Section 9.1. Work with Worksheet Objects Section 9.2. Worksheets and Worksheet Members Section 9.3. Sheets Members Section 9.4. Work with Outlines Section 9.5. Outline Members Section 9.6. Work with Ranges Section 9.7. Range Members Section 9.8. Work with Scenario Objects Section 9.9. Scenario and Scenarios Members Section 9.10. Resources Chapter 10. Linking and Embedding Section 10.1. Add Comments Section 10.2. Use Hyperlinks Section 10.3. Link and Embed Objects Section 10.4. Speak Section 10.5. Comment and Comments Members Section 10.6. Hyperlink and Hyperlinks Members Section 10.7. OleObject and OleObjects Members Section 10.8. OLEFormat Members Section 10.9. Speech Members Section 10.10. UsedObjects Members Chapter 11. Printing and Publishing Section 11.1. Print and Preview Section 11.2. Control Paging Section 11.3. Change Printer Settings Section 11.4. Filter Ranges Section 11.5. Save and Display Views Section 11.6. Publish to the Web Section 11.7. AutoFilter Members Section 11.8. Filter and Filters Members Section 11.9. CustomView and CustomViews Members Section 11.10. HPageBreak, HPageBreaks, VPageBreak, VPageBreaks Members Section 11.11. PageSetup Members Section 11.12. Graphic Members Section 11.13. PublishObject and PublishObjects Members Section 11.14. WebOptions and DefaultWebOptions Members Chapter 12. Loading and Manipulating Data Section 12.1. Working with QueryTable Objects Section 12.2. QueryTable and QueryTables Members Section 12.3. Working with Parameter Objects Section 12.4. Parameter Members Section 12.5. Working with ADO and DAO Section 12.6. ADO Objects and Members Section 12.7. DAO Objects and Members Section 12.8. DAO.Database and DAO.Databases Members Section 12.9. DAO.Document and DAO.Documents Members Section 12.10. DAO.QueryDef and DAO.QueryDefs Members Section 12.11. DAO.Recordset and DAO.Recordsets Members Chapter 13. Analyzing Data with Pivot Tables Section 13.1. Quick Guide to Pivot Tables Section 13.2. Program Pivot Tables Section 13.3. PivotTable and PivotTables Members Section 13.4. PivotCache and PivotCaches Members Section 13.5. PivotField and PivotFields Members Section 13.6. CalculatedFields Members Section 13.7. CalculatedItems Members Section 13.8. PivotCell Members Section 13.9. PivotFormula and PivotFormulas Members Section 13.10. PivotItem and PivotItems Members Section 13.11. PivotItemList Members Section 13.12. PivotLayout Members Section 13.13. CubeField and CubeFields Members Section 13.14. CalculatedMember and CalculatedMembers Members Chapter 14. Sharing Data Using Lists Section 14.1. Use Lists Section 14.2. ListObject and ListObjects Members Section 14.3. ListRow and ListRows Members Section 14.4. ListColumn and ListColumns Members Section 14.5. ListDataFormat Members Section 14.6. Use the Lists Web Service Section 14.7. Lists Web Service Members Section 14.8. Resources Chapter 15. Working with XML Section 15.1. Understand XML Section 15.2. Save Workbooks as XML Section 15.3. Use XML Maps Section 15.4. Program with XML Maps Section 15.5. XmlMap and XmlMaps Members Section 15.6. XmlDataBinding Members Section 15.7. XmlNamespace and XmlNamespaces Members Section 15.8. XmlSchema and XmlSchemas Members Section 15.9. Get an XML Map from a List or Range Section 15.10. XPath Members Section 15.11. Resources Chapter 16. Charting Section 16.1. Navigate Chart Objects Section 16.2. Create Charts Quickly Section 16.3. Embed Charts Section 16.4. Create More Complex Charts Section 16.5. Choose Chart Type Section 16.6. Create Combo Charts Section 16.7. Add Titles and Labels Section 16.8. Plot a Series Section 16.9. Respond to Chart Events Section 16.10. Chart and Charts Members Section 16.11. ChartObject and ChartObjects Members Section 16.12. ChartGroup and ChartGroups Members Section 16.13. SeriesLines Members Section 16.14. Axes and Axis Members Section 16.15. DataTable Members Section 16.16. Series and SeriesCollection Members Section 16.17. Point and Points Members Chapter 17. Formatting Charts Section 17.1. Format Titles and Labels Section 17.2. Change Backgrounds and Fonts Section 17.3. Add Trendlines Section 17.4. Add Series Lines and Bars Section 17.5. ChartTitle, AxisTitle, and DisplayUnitLabel Members Section 17.6. DataLabel and DataLabels Members Section 17.7. LeaderLines Members Section 17.8. ChartArea Members Section 17.9. ChartFillFormat Members Section 17.10. ChartColorFormat Members Section 17.11. DropLines and HiLoLines Members Section 17.12. DownBars and UpBars Members Section 17.13. ErrorBars Members Section 17.14. Legend Members Section 17.15. LegendEntry and LegendEntries Members Section 17.16. LegendKey Members Section 17.17. Gridlines Members Section 17.18. TickLabels Members Section 17.19. Trendline and Trendlines Members Section 17.20. PlotArea Members Section 17.21. Floor Members Section 17.22. Walls Members Section 17.23. Corners Members Chapter 18. Drawing Graphics Section 18.1. Draw in Excel Section 18.2. Create Diagrams Section 18.3. Program with Drawing Objects Section 18.4. Program Diagrams Section 18.5. Shape, ShapeRange, and Shapes Members Section 18.6. Adjustments Members Section 18.7. CalloutFormat Members Section 18.8. ColorFormat Members Section 18.9. ConnectorFormat Members Section 18.10. ControlFormat Members Section 18.11. FillFormat Members Section 18.12. FreeFormBuilder Section 18.13. GroupShapes Members Section 18.14. LineFormat Members Section 18.15. LinkFormat Members Section 18.16. PictureFormat Members Section 18.17. ShadowFormat Section 18.18. ShapeNode and ShapeNodes Members Section 18.19. TextFrame Section 18.20. TextEffectFormat Section 18.21. ThreeDFormat Chapter 19. Adding Menus and Toolbars Section 19.1. About Excel Menus Section 19.2. Build a Top-Level Menu Section 19.3. Create a Menu in Code Section 19.4. Build Context Menus Section 19.5. Build a Toolbar Section 19.6. Create Toolbars in Code Section 19.7. CommandBar and CommandBars Members Section 19.8. CommandBarControl and CommandBarControls Members Section 19.9. CommandBarButton Members Section 19.10. CommandBarComboBox Members Section 19.11. CommandBarPopup Members Chapter 20. Building Dialog Boxes Section 20.1. Types of Dialogs Section 20.2. Create Data-Entry Forms Section 20.3. Design Your Own Forms Section 20.4. Use Controls on Worksheets Section 20.5. UserForm and Frame Members Section 20.6. Control and Controls Members Section 20.7. Font Members Section 20.8. CheckBox, OptionButton, ToggleButton Members Section 20.9. ComboBox Members Section 20.10. CommandButton Members Section 20.11. Image Members Section 20.12. Label Members Section 20.13. ListBox Members Section 20.14. MultiPage Members Section 20.15. Page Members Section 20.16. ScrollBar and SpinButton Members Section 20.17. TabStrip Members Section 20.18. TextBox and RefEdit Members Chapter 21. Sending and Receiving Workbooks Section 21.1. Send Mail Section 21.2. Work with Mail Items Section 21.3. Collect Review Comments Section 21.4. Route Workbooks Section 21.5. Read Mail Section 21.6. MsoEnvelope Members Section 21.7. MailItem Members Section 21.8. RoutingSlip Members Part III: Extending Excel Chapter 22. Building Add-ins Section 22.1. Types of Add-ins Section 22.2. Code-Only Add-ins Section 22.3. Visual Add-ins Section 22.4. Set Add-in Properties Section 22.5. Sign the Add-in Section 22.6. Distribute the Add-in Section 22.7. Work with Add-ins in Code Section 22.8. AddIn and AddIns Members Chapter 23. Integrating DLLs and COM Section 23.1. Use DLLs Section 23.2. Use COM Applications Chapter 24. Getting Data from the Web Section 24.1. Perform Web Queries Section 24.2. QueryTable and QueryTables Web Query Members Section 24.3. Use Web Services Section 24.4. Resources Chapter 25. Programming Excel with .NET Section 25.1. Approaches to Working with .NET Section 25.2. Create .NET Components for Excel Section 25.3. Use .NET Components in Excel Section 25.4. Use Excel as a Component in .NET Section 25.5. Create Excel Applications in .NET Section 25.6. Resources Chapter 26. Exploring Security in Depth Section 26.1. Security Layers Section 26.2. Understand Windows Security Section 26.3. Password-Protect and Encrypt Workbooks Section 26.4. Program with Passwords and Encryption Section 26.5. Workbook Password and Encryption Members Section 26.6. Excel Password Security Section 26.7. Protect Items in a Workbook Section 26.8. Program with Protection Section 26.9. Workbook Protection Members Section 26.10. Worksheet Protection Members Section 26.11. Chart Protection Members Section 26.12. Protection Members Section 26.13. AllowEditRange and AllowEditRanges Members Section 26.14. UserAccess and UserAccessList Members Section 26.15. Set Workbook Permissions Section 26.16. Program with Permissions Section 26.17. Permission and UserPermission Members Section 26.18. Add Digital Signatures Section 26.19. Set Macro Security Section 26.20. Set ActiveX Control Security Section 26.21. Distribute Security Settings Section 26.22. Using the Anti-Virus API Section 26.23. Common Tasks Section 26.24. Resources Part IV: Appendixes Appendix A. Reference Tables Section A.1. Dialogs Collection Constants Section A.2. Common Programmatic IDs Appendix B. Version Compatibility Section B.1. Summary of Version Changes Section B.2. Macintosh Compatibility About the Author Colophon Index

609

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧