Click here to Skip to main content
13,291,084 members (70,569 online)
Rate this:
Please Sign up or sign in to vote.
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

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 2:39am
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?
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: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
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.
Rate this: bad
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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;
   intSnrCounter = intSnrCounter + intVorCounter + 1;
   intVorCounter = 0;

Hope this helps...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2017
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