如何将Excel表格转换到易语言数据源(表格)源码

2024-11-28 05:29:03
推荐回答(2个)
回答1:

这么久了还没有答案,看来空头支票是不行的。

要实现这个方法很麻烦也很费时间,我一时半会也写不出来,等我写好后再传上来。


写好了,下面是转换的效果,

不过我留了点私心,该程序可供测试。请采纳后再私信给你钥匙生成源码,不然我这两天就白忙了。

回答2:

用数据流. 先将数据绑定到dataview.然后如下.
注:dgvAgeWeekSex==dataview的name
private void SaveAs() //另存新档按钮 导出成Excel
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Execl files (*.xls)|*.xls";
saveFileDialog.FilterIndex = 0;
saveFileDialog.RestoreDirectory = true;
saveFileDialog.CreatePrompt = true;
saveFileDialog.Title = "Export Excel File To";
saveFileDialog.ShowDialog();
Stream myStream;
myStream = saveFileDialog.OpenFile();
StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding(-0));
string str = "";
try{ //写标题
for (int i = 0; i < dgvAgeWeekSex.ColumnCount; i++)
{
if (i > 0)
{
str += "\t";}str += dgvAgeWeekSex.Columns[i].HeaderText;
}
sw.WriteLine(str);
//写内容
for (int j = 0; j < dgvAgeWeekSex.Rows.Count; j++){string tempStr = "";
for (int k = 0; k < dgvAgeWeekSex.Columns.Count; k++)
{
if (k > 0){tempStr += "\t";}tempStr += dgvAgeWeekSex.Rows[j].Cells[k].Value.ToString();
}
sw.WriteLine(tempStr);
}
sw.Close();
myStream.Close();
}