社区
C#
帖子详情
c# listview与xls表之间的问题
cwb210
2008-11-12 09:28:16
在导入xls表时,在xls表格里某列(如列头为姓名的一列)能不能使其添加到listview控件中指定的一个列头下面?也就是说,xls表格中不管这一列在什么位子,导入的时候始终能添加到listview中指定的列头下,能实现吗?
...全文
172
5
打赏
收藏
c# listview与xls表之间的问题
在导入xls表时,在xls表格里某列(如列头为姓名的一列)能不能使其添加到listview控件中指定的一个列头下面?也就是说,xls表格中不管这一列在什么位子,导入的时候始终能添加到listview中指定的列头下,能实现吗?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
cwb210
2008-11-12
打赏
举报
回复
列头是怎么定位的呢?就是listview怎么定位某个列头?表格里取我会,就这列头不知道怎么定位
cpio
2008-11-12
打赏
举报
回复
先全部取出来,然后再循环找列头为姓名那行,把它的值给表头,然后删除那一行
devilli
2008-11-12
打赏
举报
回复
帮顶
j45kp
2008-11-12
打赏
举报
回复
private static string ProcessExcel(IList<ProblemCodeRawdataInfo> list, string path, string virtualPath)
{
string timeFlag = DateTime.Now.ToFileTime().ToString();
string dirStr = path + DateTime.Now.ToFileTime().ToString();
System.IO.Directory.CreateDirectory(dirStr);
int fileNum = 1;
//不通过OLE生成excel文件的方法
for (int index = 0; index < list.Count; index++)
{
ProblemCodeExcel excel = new ProblemCodeExcel(GenFileName(dirStr + "\\"));
excel.BeginWrite();
excel.WriteHeader();
Console.WriteLine("正在生成第" + fileNum.ToString() + "个文档.....");
for (ushort row = 1; row < ushort.MaxValue && index < list.Count; row++, index++)
{
if (list[index] != null)
{
excel.WriteString(row, 0, list[index].CreateDate);
excel.WriteString(row, 1, list[index].CaseId);
excel.WriteString(row, 2, list[index].Country);
excel.WriteString(row, 3, list[index].Datasource);
excel.WriteString(row, 4, list[index].Engineer);
excel.WriteString(row, 5, list[index].Model);
excel.WriteString(row, 6, list[index].Problem);
excel.WriteString(row, 7, list[index].ProblemCode);
excel.WriteString(row, 8, list[index].ProblemDesc);
excel.WriteString(row, 9, list[index].ProblemType);
excel.WriteString(row, 10, list[index].ProblemTypeDesc);
excel.WriteString(row, 11, list[index].ProductType);
excel.WriteString(row, 12, list[index].Reply);
excel.WriteString(row, 13, list[index].Series);
excel.WriteString(row, 14, list[index].Server);
excel.WriteString(row, 15, list[index].Subject);
excel.WriteString(row, 16, list[index].SubSeries);
}
else
break;
}
Console.WriteLine("生成成功!");
excel.EndWrite();
index--;
fileNum++;
}
ZipDAO dao = new ZipDAO(dirStr);
dao.ZipFold();
DeleteFile(dirStr);
Console.WriteLine("处理完毕");
Thread.Sleep(1000);
return virtualPath + timeFlag + ".rar";
}
public class ExcelWriter
{
System.IO.FileStream _wirter;
public ExcelWriter(string strPath)
{
_wirter = new System.IO.FileStream(strPath, System.IO.FileMode.OpenOrCreate);
}
/// <summary>
/// 写入short数组
/// </summary>
/// <param name="values"></param>
private void _writeFile(ushort[] values)
{
foreach (ushort v in values)
{
byte[] b = System.BitConverter.GetBytes(v);
_wirter.Write(b, 0, b.Length);
}
}
/// <summary>
/// 写文件头
/// </summary>
public void BeginWrite()
{
_writeFile(new ushort[] { 0x809, 8, 0, 0x10, 0, 0 });
}
/// <summary>
/// 写文件尾
/// </summary>
public void EndWrite()
{
_writeFile(new ushort[] { 0xa, 0 });
_wirter.Close();
}
/// <summary>
/// 写一个数字到单元格x,y
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="value"></param>
public void WriteNumber(ushort x, ushort y, double value)
{
_writeFile(new ushort[] { 0x203, 14, x, y, 0 });
byte[] b = System.BitConverter.GetBytes(value);
_wirter.Write(b, 0, b.Length);
}
/// <summary>
/// 写一个字符到单元格x,y
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="value"></param>
public void WriteString(ushort x, ushort y, string value)
{
byte[] b = System.Text.Encoding.UTF8.GetBytes(value);
_writeFile(new ushort[] { 0x204, (ushort)(b.Length + 8), x, y, 0, (ushort)b.Length });
_wirter.Write(b, 0, b.Length);
}
}
xylys521
2008-11-12
打赏
举报
回复
问一下!xls能添加到listview中吗?
是不是应该先将数据取出放到数据源中(DataTable)
然后绑定不就可以了。
你还管他列在哪里干吗
listview
导出到
xls
取当前时间为文件名
xls
导入到
listview
本文介绍了一个使用
C#
编写的简单程序,该程序能够从
ListView
导出数据到Excel文件,并能将数据从指定的Excel文件(.
xls
)导入到
ListView
中。导出功能通过创建SaveFileDialog来让用户选择保存位置,并使用StreamWriter将
ListView
的内容写入Excel文件。导入功能则通过读取指定路径的文件,解析每一行的数据并填充到
ListView
中。
C#
从
ListView
导出到Excel
本文介绍如何使用
C#
将
ListView
中的数据导出到Excel文件,包括设置Excel工作簿、工作
表
,格式化单元格,以及将
ListView
项转换为Excel数据。
C#
中
ListView
导出Excel
本文介绍了一种将
ListView
中的数据导出到Excel的方法,包括处理不同情况下的
ListView
(如带CheckBox的
ListView
)以及如何使用Microsoft.Office.Interop.Excel库进行操作。
C#
ListView
数据导出到Excel
本文介绍了一种将ASP.NET中的
ListView
控件数据导出到Excel的方法。通过使用StreamWriter类来创建并写入数据,实现了从
ListView
控件到Excel文件的数据转换。此过程包括设置SaveFileDialog来让用户选择保存路径,并通过遍历
ListView
的列标题和数据项来构造Excel文件的内容。
C#
中
ListView
数据导出excel
表
本文介绍了一个使用
C#
将CDR数据转换为Excel文件的过程,包括创建Excel对象、添加工作簿、设置工作
表
格式和填充数据。
C#
111,130
社区成员
642,541
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章