excel表格导出的问题

cwb210 2008-09-04 05:24:57
把数据生成excel表完成后,能不能把显示在textbox控件的数量总和也生成到excel表格上?(注:数据是从listview控件上生成到excel表格上的),要怎么样实现这个目的,或是思路什么的提供下阿
...全文
168 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cwb210 2008-09-05
  • 打赏
  • 举报
回复
没人来吗 那我自己ding
cwb210 2008-09-05
  • 打赏
  • 举报
回复
怎么没人帮忙看看哦
honkerhero 2008-09-04
  • 打赏
  • 举报
回复
好强大的swicth/case
fj2084 2008-09-04
  • 打赏
  • 举报
回复
wwwwwww
cwb210 2008-09-04
  • 打赏
  • 举报
回复
private void btnOutput_Click(object sender, System.EventArgs e)
{
try
{
Excel.Application xlApp = new Excel.ApplicationClass();
xlApp.Visible = true;
Excel.Workbook xlBook =xlApp.Workbooks.Add(true);

// for( int i =0;i<lvView.Columns.Count;i++ )
// {
// xlApp.Cells[1,i+1] = lvView.Columns[i].Text;
// }

xlApp.Cells[1,1] = "序号";
xlApp.Cells[1,2] = "产品编号";
xlApp.Cells[1,3] = "产品名称";
xlApp.Cells[1,4] = "颜色";
xlApp.Cells[1,5] = "规格";
xlApp.Cells[1,6] = "数量";
xlApp.Cells[1,7] = "单价";
xlApp.Cells[1,8] = "备注";

for( int iRow=0;iRow<lvView.Items.Count;iRow++ )
{

xlApp.Cells[iRow+2,1] = "'" + iRow; // lvView.Items[iRow].SubItems[iCol].Text;
xlApp.Cells[iRow+2,2] = "'" + lvView.Items[iRow].SubItems[0].Text;
xlApp.Cells[iRow+2,3] = "'" + lvView.Items[iRow].SubItems[1].Text;
xlApp.Cells[iRow+2,4] = "'" + lvView.Items[iRow].SubItems[2].Text;
xlApp.Cells[iRow+2,5] = "'" + GetGuige(lvView.Items[iRow].SubItems[0].Text);
xlApp.Cells[iRow+2,6] = "'" + lvView.Items[iRow].SubItems[3].Text;
xlApp.Cells[iRow+2,7] = "'" + lvView.Items[iRow].SubItems[4].Text;
xlApp.Cells[iRow+2,8] = "'";

}


// for( int iRow=0;iRow<lvView.Items.Count;iRow++ )
// {
// for( int iCol=0;iCol<lvView.Columns.Count;iCol++ )
// {
// xlApp.Cells[iRow+2,iCol+1] = "'" + lvView.Items[iRow].SubItems[iCol].Text;
// }
// }

// for( int iRow = 0;iRow<dtMain.Rows.Count;iRow++ )
// {
// for( int iCol =0;iCol<dtMain.Columns.Count;iCol++ )
// {
// if( iCol ==1)
// {
// xlApp.Cells[iRow+2,iCol+1] = "'" +dtMain.Rows[iRow][iCol].ToString().Trim();
// }
// else
// {
// xlApp.Cells[iRow+2,iCol+1] = dtMain.Rows[iRow][iCol];
// }
// }
// }
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
private string GetGuige(string sCode)
{
if( sCode.Length != 10)
return "";
string sGuige = "";
sGuige = sCode.Substring(4,1);
switch(sGuige)
{
case "A":
case "B":
case "C":
case "D":
case "E":
case "F":
case "G":
case "a":
case "b":
case "c":
case "d":
case "e":
case "f":
case "g":
return sGuige;
default :
return "";
}这2段代码是导数据的过程
下面是我后来加上去的,不知道怎么使其加到那个导数据的过程中!!
private void lvView_SelectedIndexChanged(object sender, System.EventArgs e)
{
int isum = 0;
for (int i = 0; i<lvView.Items.Count;i++)
{
isum += Convert.ToInt32(lvView.Items[i].SubItems[3].Text);
}
this.tB2.Text = isum.ToString();
}
cwb210 2008-09-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhangzeshuai 的回复:]
如果你是把excel做为ODBC数据源.用sql写
如果你是把excel打开读写,直接写cell值就可以了.
[/Quote]
是这样的,因为这个软件是配货用的,(已经完成的软件,而我是新学@_@)不是把excel表作数据源用的所以,只是在配好货的时候从软件中导出数据,而我现在这个数量的总数是我后来另外写的,我想实现在数据导到表格上后,能不能把我写的显示在textbon控件中的总数一同导入在表格上,给个头绪思想什么的也行,我现在无处下手
chkmouse 2008-09-04
  • 打赏
  • 举报
回复
lz 可不可以把代码给我借鉴下呀
行者无疆-Kevin 2008-09-04
  • 打赏
  • 举报
回复
如果你是把excel做为ODBC数据源.用sql写
如果你是把excel打开读写,直接写cell值就可以了.

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧