Excel转Csv
using System;
using System.IO;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Excel;
public static class ExcelToCsv
{
public static bool Convert(string source, string target, Encoding encoding)
{
Excel.Application oXL = new Excel.Application();
oXL.Visible = false;
oXL.DisplayAlerts = false;
Excel.Workbooks workbooks = oXL.Workbooks;
Workbook mWorkBook = workbooks.Open(source, 0, false, 5, "", "", false, XlPlatform.xlWindows, "", true, false, 0, true, false, false);
mWorkBook.SaveAs(target, XlFileFormat.xlCSV,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, false);
mWorkBook.Close(Type.Missing, Type.Missing, Type.Missing);
mWorkBook = null;
if (oXL != null)
{
oXL.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL);
oXL = null;
}
File.WriteAllText(target, File.ReadAllText(target, Encoding.Default), encoding);
return true;
}
}