本文整理汇总了C#中Worksheet.SaveAs方法的典型用法代码示例。如果您正苦于以下问题:C# Worksheet.SaveAs方法的具体用法?C# Worksheet.SaveAs怎么用?C# Worksheet.SaveAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Worksheet
的用法示例。
在下文中一共展示了Worksheet.SaveAs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveExcelFile
public static void SaveExcelFile(string fileName, string tempFileName,string[,] contents, int startColumn, int startRow)
{
try
{
excelApp = new ApplicationClass();
Workbooks myWorkBooks = excelApp.Workbooks;
myWorkBooks.Open(tempFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Sheets sheets = excelApp.Sheets;
mySheet1 = (Worksheet)sheets[1];
mySheet1.Activate();
//写入测试信息
Range range1 = mySheet1.get_Range(mySheet1.Cells[startRow, startColumn], mySheet1.Cells[contents.GetLength(0)+startRow-1,contents.GetLength(1)+startColumn-1]);
range1.Value2 = contents;
mySheet1.SaveAs(fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing);
myWorkBooks.Close();
excelApp.Quit();
excelApp = null;
}
catch (Exception ee)
{
throw ee;
}
}
示例2: SaveWorkSheet
static void SaveWorkSheet(Worksheet sheet, string csvFileName, XlFileFormat format, bool quiet, bool prompt)
{
if(!quiet) Console.Error.WriteLine("Saving worksheet {0} to file '{1}'", sheet.Name, csvFileName);
csvFileName = Path.Combine(Environment.CurrentDirectory, csvFileName);
if (File.Exists(csvFileName))
{
if (prompt)
{
Console.Error.Write("The file {0} exists. Replace (Y/n)?", Path.GetFileName(csvFileName));
var input = Console.ReadLine();
if (input == "n") return;
}
File.Delete(csvFileName);
}
sheet.SaveAs(csvFileName, format);
}