WorkBook的SaveAs方法 2

-----转载:http://blog.csdn.net/zyming0815/article/details/5939104

语法

声明
Sub SaveAs ( _
     Filename As Object, _
     FileFormat As Object, _
     Password As Object, _
     WriteResPassword As Object, _
     ReadOnlyRecommended As Object, _
     CreateBackup As Object, _
     AccessMode As XlSaveAsAccessMode, _
     ConflictResolution As Object, _
     AddToMru As Object, _
     TextCodepage As Object, _
     TextVisualLayout As Object, _
     Local As Object _
)
参数
Filename
类型:System.Object
要保存的文件的名称。可以包含完整路径;否则,Microsoft Office Excel 将文件保存在当前文件夹中。

 

FileFormat
类型:System.Object
XlFileFormat 值之一,指定保存文件时要使用的文件格式。对于现有文件,默认格式为最后一种指定文件格式;对于新文件,默认格式为所用 Excel 版本的格式。

 

Password
类型:System.Object
一个区分大小写的字符串(不超过 15 个字符),指示为文件指定的保护密码。

 

WriteResPassword
类型:System.Object
文件的写保护密码。如果保存文件时指定了密码,但打开文件时没有提供密码,则该文件以只读方式打开。

 

ReadOnlyRecommended
类型:System.Object
如果为 true,则在打开该文件时显示一条消息,建议以只读方式打开该文件。

 

CreateBackup
类型:System.Object
如果为 true,则创建备份文件。

AccessMode
类型:Microsoft.Office.Interop.Excel.XlSaveAsAccessMode
XlSaveAsAccessMode 值之一。

ConflictResolution
类型:System.Object
XlSaveConflictResolution 值之一。

 

AddToMru
类型:System.Object
如果为 true,则将工作簿添加到最近使用的文件列表中。默认值为 false。

 

TextCodepage
类型:System.Object
对于 Microsoft Excel 中的所有语言均忽略。

说明 
当 Excel 将工作簿保存为 CSV 或文本格式之一(使用 FileFormat 参数指定)时,它使用与当前计算机上使用的系统区域设置语言相对应的代码页。
 

TextVisualLayout
类型:System.Object
对于 Microsoft Excel 中的所有语言均忽略。

说明 
当 Excel 将工作簿保存为 CSV 或文本格式之一(使用 FileFormat 参数指定)时,它会以逻辑布局保存这些格式。如果在文件中从右到左的文本内嵌入从左到右的文本,逻辑布局会按照文件中所有语言的正确读取顺序保存文件内容,而不管方向如何,反之亦然。当使用应用程序打开文件时,系统会根据代码页中的字符值范围按照正确方向呈现每一连串字符中的字符。(在用于显示文件的精确内存布局的应用程序(如调试器或编辑器)中打开该文件时例外。)
 

Local
类型:System.Object
如果为 true,则按照 Excel(包括控制面板设置)的语言保存文件。如果为 false(默认值),则按照 Visual Basic for Applications (VBA) 的语言保存文件。

 

备注
--------------------------------------------------------------------------------

Visual Studio 不支持将工作簿保存为共享工作簿。

----------------------------------------------------------------------------------------------------------------------------------

object missing = System.Reflection.Missing.Value;
myWorkbook.SaveAs(fileallpath,Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,missing,missing,missing,missing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,missing,missing,missing,missing,missing);

 第二个参数使用xlWorkbookNormal则输出的是xls格式,如果使用的是missing则输出系统中带有的EXCEL支持的格式

一、SAVEAS方法详解

expression.SaveAs(FileName,FileFormat,Password,WriteResPassword,ReadOnlyRecommended,CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)       

expression   必需。该表达式返回上述对象中一个对象。

Filename    Variant类型,可选。该字符串表示要保存的文件名。可包含完整路径。如果不指定路径,Microsoft Exce 将文件保存到当前文件夹中。  

FileFormat  Variant 类型,可选。保存文件时使用的文件格式。要得到有效选项的列表,请参阅   FileFormat   属性。对于已有文件,其默认格式是上次指定的文件格式;对于新文件,默认格式为当前使用的   Excel   版本格式。

Password  Variant 类型,可选。它是一个区分大小写的字符串(最长不超过15个字符),用于指定文件的保护密码。

WriteResPassword  Variant类型,可选。该字符串表示文件的写保护密码。如果文件保存时带有密码,但打开文件时不输入密码,则该文件以只读方式打开。

ReadOnlyRecommended  Variant类型,可选。如果该值为True,则在打开文件时显示一条信息,提示该文件以只读方式打开。

CreateBackup  Variant类型,可选。如果该值为True,则创建备份文件。 

AccessMode   XlSaveAsAccessMode类型,可选。
        XlSaveAsAccessMode   可为以下 XlSaveAsAccessMode 常量之一。
        xlExclusive     (不含方式)
        xlNoChange   default     (不更改访问方式)
        xlShared     (共享列表)   
        如果省略此参数,则不会更改访问方式。如果在没有改变文件名的情况下保存共享列表,则可以忽略参数。若要改变访问方式,请使用   ExclusiveAccess   方法。  

ConflictResolution  XlSaveConflictResolution   类型,可选。 
      XlSaveConflictResolution   可为以下   XlSaveConflictResolution   常量之一。
      xlUserResolution     (显示冲突解决方案对话框)
      xlLocalSessionChanges   (自动接受本地用户的修改)
      xlOtherSessionChanges     (接受除本地用户之外的其他用户的更改)
        如果忽略本参数,则显示冲突处理对话框。

AddToMru  Variant 类型,可选。如果该值为True,则将该工作簿添加到最近使用的文件列表中。默认值为False。     

TextCodePage   Variant类型,可选。不在美国英语版的Microsoft Excel中使用。    

TextVisualLayout Variant类型,可选。不在美国英语版的Microsoft Excel中使用。

 Local       Variant  类型,可选。如果该值为True,则以Microsoft Excel(包括控制面板设置)的语言保存文件。如果该值为False(默认值),则以Visual Basic for Applications (VBA) 的语言保存文件,其中   Visual Basic for Applications(VBA)为典型安装的美国英语版本,除非VBA 项目中的Workbooks.Open来自旧的国际化的XL5/95 VBA项目。

二、Microsoft.Office.Interop.Excel.XlFileFormat的一些常量值说明

Member nameDescription
xlAddIn Microsoft Office Excel Add-In.
xlCSV Comma separated value.
xlCSVMac Comma separated value.
xlCSVMSDOS Comma separated value.
xlCSVWindows Comma separated value.
xlCurrentPlatformText Specifies a type of text format
xlDBF2 Dbase 2 format.
xlDBF3 Dbase 3 format.
xlDBF4 Dbase 4 format.
xlDIF Data Interchange format.
xlExcel2 Excel version 2.0.
xlExcel2FarEast Excel version 2.0 far east.
xlExcel3 Excel version 3.0.
xlExcel4 Excel version 4.0.
xlExcel4Workbook Excel version 4.0. Workbook format.
xlExcel5 Excel version 5.0.
xlExcel7 Excel 95.
xlExcel9795 Excel version 95 and 97.
xlHtml Web page format.
xlIntlAddIn Microsoft Office Excel Add-In international format.
xlIntlMacro Deprecated format.
xlSYLK Symbolic link format.
xlTemplate Excel template format.
xlTextMac Specifies a type of text format.
xlTextMSDOS Specifies a type of text format.
xlTextPrinter Specifies a type of text format.
xlTextWindows Specifies a type of text format.
xlUnicodeText Specifies a type of text format.
xlWebArchive MHT format.
xlWJ2WD1 Deprecated format.
xlWJ3 Deprecated format.
xlWJ3FJ3 Deprecated format.
xlWK1 Lotus 1-2-3 format.
xlWK1ALL Lotus 1-2-3 format.
xlWK1FMT Lotus 1-2-3 format.
xlWK3 Lotus 1-2-3 format.
xlWK3FM3 Lotus 1-2-3 format.
xlWK4 Lotus 1-2-3 format.
xlWKS Lotus 1-2-3 format.
xlWorkbookNormal Excel workbook format.
xlWorks2FarEast Microsoft Works 2.0 format
xlWQ1 Quattro Pro format.
xlXMLSpreadsheet Excel Spreadsheet format.

三、关于C#中对EXCEL表格进行处理的资料

http://www.dotblogs.com.tw/yc421206/archive/2012/03/09/70624.aspx

四、修改EXCEL文件右键属性中的文件备注
http://msdn.microsoft.com/zh-tw/library/microsoft.office.tools.word.document.builtindocumentproperties
例如:
myWorkbook.BuiltinDocumentProperties["Title"] = “DATA”;
myWorkbook.BuiltinDocumentProperties["Author"] = “NO”;

原文地址:https://www.cnblogs.com/tianma3798/p/3499561.html