C#Execel格式化 [英] C# Execel Formatting

查看:122
本文介绍了C#Execel格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好所有



我从gridview生成了一个excel文件,看起来像这样

hello all

I have generated an excel file from a gridview which looks like this

Electronics	Home Appliances	AC	2.00 TON	VOLTAS
Electronics	Home Appliances	AC	2.00 TON	LG
Electronics	Home Appliances	AC	2.00 TON	Whirlpool







但是我想要一些格式同样想要输出像




but I want some formatting on the same and want an output like

Electronics	Home Appliances	AC	2.00 TON	VOLTAS
				                        LG
				                        Whirlpool





我已经尝试了很多但没有任何结果。一点帮助将受到高度赞赏。感谢所有提前



I have tried a lot but without any result. A little help will be highly appreciated. Thanks to all in advance

推荐答案

当使用Excel做任何关于格式化的事情或类似的事情时,你最好的选择就是让你的应用生成电子表格。在电子表格中打开数据后,在Excel中打开它 - 转到开发人员工具栏 - 开始录制marco - 进行更改 - 停止宏 - 查看生成的vba代码并将其转换为c#并将该代码添加到创建电子表格的函数的结尾。这就是我总是在Excel中完成我的格式和诸如此类的东西。请记住,创建的vba将引用一些对象和枚举,检查msdn,它们在那里有定义。



另外请记住,那些marcos基本上都运行在一个

When doing anything with Excel regarding formatting or anything like that your best bet, in this case, would be to let your app generate the spreadsheet. Once you have your data in the spreadsheet open it in Excel - go to the developer toolbar - start recording a marco - make your changes - stop the macro - take a look at the generated vba code and convert that into c# and add that code to the end of your function that creates the spreadsheet. This is how i have always done my formatting and whatnot in Excel. Just keep in mind that the vba that is created will reference a few objects and enums, check the msdn they have the definitions for them there.

Also keep in mind that those marcos basically run inside a
With Excel.Application
   ... 
End With






我有这样的问题。我使用COM-Interop而不是OleDB连接,并通过我的ojbjects迭代我们的内部集合在一个双foreach循环中:



Hi,

I''ve had a "problem" like this. I used the COM-Interop instead of OleDB connection and iterated through my ojbjects with their inner collections in a double foreach-loop:

foreach (Outerobject oO in Outerobjects)
{
   split = oO.strSachnummer.Split('\\');
   split = split.Last().Split('.');
   exWks.Cells[intSnrCounter, 1] = split.First() ;

   foreach (Innerobjects iO in oO.Innerobjects)
   {
      exWks.Cells[intSnrCounter + intVorCounter, 2] = iO.strArbeitsgangtext;
      exWks.Cells[intSnrCounter + intVorCounter, 3] = iO.strVorrichtungsnummer;
      intVorCounter++;
   }

   intSnrCounter = intSnrCounter + intVorCounter + 1;
   intVorCounter = 0;
}





希望这会有所帮助......



Hope this helps...


这篇关于C#Execel格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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