2012-10-25 70 views
0

您好我不得不进口值输入到Excel文件以下列方式:擅长值

值必须进口基础上的每一行即00004100. 最后8个字设00004为column5 100是第6列。

我需要为每个唯一的column5和column6对将值导入单独的Excel表单。即最后8位数字为00002100的所有行都将放入一张Excel表格中,依此类推。

1234 john smith america 00002100 
1234 john smith america 00002100 
1234 john smith america 00002200 
1234 john smith america 00002200 
1234 john smith america 00003100 
1234 john smith america 00003200 
1234 john smith america 00003200 
1234 john smith america 00004100 
1234 john smith america 00002100 

如何根据vb中的给定条件生成excel表单?

Thanx提前!

+1

这个问题不是很清楚。你想使用VBA-Excel或VB.Net吗?他们都不同... –

回答

0

我不确定为什么这是一个VB问题?你使用Interop吗? 由于我不知道这一点,我使用伪代码 - 但我认为你会明白。 它更像vb.net - 如果你使用vba,一般的想法会起作用。

一般我会对以下内容:遍历每一行,并集中一个新的字符串。 喜欢倾向:

For row = 0 to rows.count-1 
dim str as new stringbuilder() 


for col = 0 to rows(row).count-1 
    str.append(rows(row).item(col) 
next 

dim lasteight=str.tostring 
lasteight=lasteight.substring(lasteight.length-8) 

'here do the following: have a list of your sheetnames. If this list contains lasteight goto this page and append the row. if no sheet exist, create one and append as well. 
next 
+0

thnx! Ishall看看这个...... 我正在使用一个excel模板,每创建一个新的值列表就会被复制。然后使用open xml填充每个要生成的报告的值以及其他要合并的数据。 – chubhub