Click here to Skip to main content
12,632,113 members (26,073 online)
Rate this:
 
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 2:39am
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.
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161208.2 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2016
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