Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Zoltán Zörgő 27-Dec-12 7:56am    
"I have tried a lot but without any result." Really? Without any result? What exactly have you tried?
rajsaksena 27-Dec-12 8:05am    
I have tried some formatting with code like checking the newly generated row for same category or group name which should not get printed.. didn't find any relevant solution on net
Suvabrata Roy 27-Dec-12 8:02am    
You can group the Columns and then write the output in an excel.
rajsaksena 27-Dec-12 8:09am    
i have the values in a data table, is it possible to group by the columns in a datatable
Suvabrata Roy 27-Dec-12 8:19am    
What is your framework, if 3.5 or higher then you can use Linq.

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
VB
With Excel.Application
   ... 
End With
 
Share this answer
 
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:

C#
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...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900