Save an Excel file as a CSV file

Source: Internet
Author: User

The method is as follows:

C #
public virtual void SaveAs (    [OptionalAttribute] Object Filename,    [OptionalAttribute] Object FileFormat,    [OptionalAttribute] Object Password,    [OptionalAttribute] Object WriteResPassword,    [OptionalAttribute] Object ReadOnlyRecommended,    [OptionalAttribute] Object CreateBackup,    [OptionalAttribute] XlSaveAsAccessMode AccessMode,    [OptionalAttribute] Object ConflictResolution,    [OptionalAttribute] Object AddToMru,    [OptionalAttribute] Object TextCodepage,    [OptionalAttribute] Object TextVisualLayout,    [OptionalAttribute] Object Local)

 

Parameters
Filename

The name of the file to save. It can contain the full path. Otherwise, Microsoft Office Excel saves the file in the current folder.

Fileformat

The format used to save the file. For a list of valid options, see the fileformat attribute. For existing files, the default format is the last specified file format. For new files, the default format is the Excel version used.

Password

A case-sensitive string (up to 15 characters) that specifies the password to protect the file.

Writerespassword

File write protection password. If a password is specified when the file is saved, but the password is not provided when the file is opened, the file is read-only.

Readonlyrecommended

IfTrue, A message is displayed when the file is opened. We recommend that you open the file in read-only mode.

Createbackup

IfTrueTo create a backup file.

Accessmode

One of the xlsaveasaccessmode values.

Conflictresolution

Xlsaveconflictresolution value.

Addtomru

IfTrueTo add the workbook to the list of recently used files. The default value isFalse.

Textcodepage

It is not used in the US English version of Excel.

Textvisuallayout

It is not used in the US English version of Excel.

Local

IfTrueSave the file according to the language of Excel (including control panel settings. IfFalse(Default), save the file according to the language of Visual Basic for Applications (VBA.

The Code is as follows:

/// Excelfilename exce file path

/// Csvfilename CSV file path

Public static void saveasexcel (string excelfilename, string csvfilename)
{
// Define a com hollow object (similar to null)
Object missing = system. reflection. Missing. value;

// Create an Excel application object (which will help us start the Excel process)
Excel. Application APP = new excel. applicationclass ();

Workbook WB = app. application. workbooks. open (excelfilename, missing, missing );
// If no prompt is displayed, use the default option
App. application. displayalerts = false;
// Do not run the Excel Interface
App. application. Visible = false;

Excel. worksheet sheet = (Excel. worksheet) WB. worksheets ["sheet1"];
// Save it as a CSV job. Pay attention to the Excel. xlfileformat. xlcsv parameter. Save it as another format and set it here
Sheet. saveas (csvfilename, Excel. xlfileformat. xlcsv, missing, missing, false, missing, missing, false );

WB. Close (false, missing, missing );

App. Quit ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.