Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 27-Dec-12 1:39am
Comments
Zoltán Zörgő at 27-Dec-12 7:56am
   
"I have tried a lot but without any result." Really? Without any result? What exactly have you tried?
rajsaksena at 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 at 27-Dec-12 8:02am
   
You can group the Columns and then write the output in an excel.
rajsaksena at 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 at 27-Dec-12 8:19am
   
What is your framework, if 3.5 or higher then you can use Linq.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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...
  Permalink  

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

  Print Answers RSS
0 CPallini 345
1 BillWoodruff 324
2 George Jonsson 279
3 Sergey Alexandrovich Kryukov 258
4 OriginalGriff 227
0 OriginalGriff 5,050
1 CPallini 4,225
2 Sergey Alexandrovich Kryukov 3,639
3 George Jonsson 2,911
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100