C#将MS Excel列转换为utf-8,然后转换为base64
我有一种情况,我必须将excel单列转换为utf-8,然后再转换为base64。C#将MS Excel列转换为utf-8,然后转换为base64,excel,c#-4.0,ado.net,Excel,C# 4.0,Ado.net,我有一种情况,我必须将excel单列转换为utf-8,然后再转换为base64。我读过几篇文章,建议如何读取excel文件。 但我不确定在我的情况下,哪种方法是最好的。 我有2MB的大文件 请建议我。我得到了解决方案 但是这和utf8和base64有什么关系呢?我还在努力,但我有了一个想法。我已经更新了我的答案,看一看。 using System; using System.Drawing; using System.Windows.Forms; using Excel = Microsof
我读过几篇文章,建议如何读取excel文件。
但我不确定在我的情况下,哪种方法是最好的。
我有2MB的大文件
请建议我。我得到了解决方案
但是这和utf8和base64有什么关系呢?我还在努力,但我有了一个想法。我已经更新了我的答案,看一看。
using System;
using System.Drawing;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
bgw.RunWorkerAsync();
var myConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\Language_Batch1_OneClick.xls';Extended Properties=Excel 8.0;"); ;
var myCommand = new OleDbCommand();
var upCommand = new OleDbCommand();
int i = 0;
try
{
string sql = null;
myConnection.Open();
myCommand.Connection = myConnection;
sql = "select ANSWER_CODE,Punjabi from [Batch_Lang_1$]";
myCommand.CommandText = sql;
var dataReader = myCommand.ExecuteReader();
while (dataReader.Read())
{
var langText = Convert.ToBase64String(Encoding.UTF8.GetBytes(dataReader["Punjabi"].ToString()));
if (langText.Length >= 1000)
{
continue;
}
var ansCode = dataReader["ANSWER_CODE"].ToString();
sql = "update [Batch_Lang_1$] set Punjabi= '" + langText + "' where ANSWER_CODE='" + ansCode + "'";
upCommand.Connection = myConnection;
upCommand.CommandText = sql;
upCommand.ExecuteNonQuery();
i++;
}
}
}
}