DataGridview和互操作 [英] DataGridview and interop

查看:127
本文介绍了DataGridview和互操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个包含Producnames,数量和价格的网格,我想在xls文件中插入所有信息.

在行上的范围是B27(产品名称)M27(数量)和O27

所有范围都是B27-B45

我可以将它们插入文件中,但问题是在网格中我可能是10种产品,我不知道如何将它们导出到xls.我怎样才能使我认为我需要arraylist

请给我一些建议.

Hello everybody

I have grid which contains Producnames , quantity and price i want to insert all informations in xls file.

On rows range is B27(productName) M27 (quantity) and O27

all range is B27 - B45

I i can insert them in my file but problem is that in my grid i possible to be 10 products i dont know how export them to xls. how can i make that i think i need arraylist

Please Advice me something.

Thanks.

推荐答案

更正我,如果我错了,您要从第27行开始将网格中的数据复制到B,M和O列中的excel. br/>
如果您有网格的数据源,则可以遍历网格并写入Excel.在这里,可以帮助您从假设您有一个数据表作为datagridview的数据源开始的事情.
Correct me if I am wrong, you want to copy data in your grid to a excel in column B, M and O from rows 27 onwards.

If you have a data source for the grid, you can loop through it and write to the excel. Here something that can help you to begin with assuming you have a data table as the data source of the datagridview.
for(int rowIndex = 0; rowIndex < rowCount; rowIndex++)
{
    for(int colIndex = 0; colIndex < colCount; colCount++)
    {
        sheetObject.get_Range("cellPositionHere",Reflection.MissingValue).Value = dataSource[rowIndex][ColIndex].ToString();
    }
}



看看 [ ^ ]文章以获取更多帮助.通过数组写入数据肯定比逐个单元地写入要快得多.但这取决于您使用的数据源.如果将数据源转换为数组要比逐个单元地写入数据花费更多的精力,则可以忽略这一点.



Take a look at this[^] article for more help. Writing data through arrays is certainly much faster than writing cell by cell. But this depends on the data source you are using. If the converting data source to array takes more effort than writing data cell by cell, you can ignore that.


这篇关于DataGridview和互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆