C#,VB.NET 如何将Excel转换为Text

 

在工作中,有时大家要求转移文档的格式,此前已经跟我们介绍过了何等将Excel转换为PDF。后天将与大家分享什么将Excel转换为Text。这一次自个儿动用的仍然是免费版的Spire.XLS
for .NET组件。

Free Spire.XLS for
.NET组件可以使开发人员在任何.NET应用程序上创办、管理和操作Excel文档。即便不设置Microsoft
Office,它也能将Excel转换为PDF,HTML,Image,CSV以及XML等。如需下载,请访问:https://www.e-iceblue.com/Download/download-excel-for-net-free.html

 

详尽步骤:

手续1:新建一个工作簿

Workbook workbook = new Workbook();

步骤2:加载需求转移的Excel文档

workbook.LoadFromFile(@"C:\Users\Administrator\Desktop\国家分布.xlsx");

手续3:获取第四个工作表

Worksheet sheet = workbook.Worksheets[0];

步骤4:将率先个工作表保存为.txt文档格式

sheet.SaveToFile("ExceltoTxt.txt", " ", Encoding.UTF8);

 

以下是更换前和转换后的对照图:

                                                                         
转换前

图片 1

                                                                   
转换后

          图片 2

 

C#完整代码:

using Spire.Xls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace excel_to_text
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"C:\Users\Administrator\Desktop\国家分布.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToFile("ExceltoTxt.txt", " ", Encoding.UTF8);

        }
    }
}

 

VB.NET完整代码:

Imports Spire.Xls
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text

Namespace excel_to_text
    Class Program
        Private Shared Sub Main(args As String())
            Dim workbook As New Workbook()
            workbook.LoadFromFile("C:\Users\Administrator\Desktop\国家分布.xlsx")
            Dim sheet As Worksheet = workbook.Worksheets(0)
            sheet.SaveToFile("ExceltoTxt.txt", " ", Encoding.UTF8)

        End Sub
    End Class
End Namespace

感激您的浏览。

相关文章