0

i need to create and download a excel sheet in c# asp.net. I used writing Range. because it is fast. but i need to format the excel sheet. According to a property(usercolor) of the user object, i need to color the row. but when writing to range how can i do that?

i am using this code to write
var startCell = (Range)sheet.Cells[2, 1]; var endCell = new object(); endCell = (Range)sheet.Cells[(usersList.Count + 2), noofcolums]; var writeRange = sheet.get_Range(startCell, endCell); writeRange.Value2 = data;

data is a TwoDimensionalObject. it is created by user object.

rwe
  • 177
  • 1
  • 1
  • 11

4 Answers4

2

As an additional comment: Do NOT use Excel in a server inevironment. It is slow and Excel might spawn error-windows at any time, causing a hang. This cannot be circumvented in a clean way - even Microsoft agrees and does not support office in a server model. You might try epplus, a free reading / writing library for excel. It is fast , supports formatting and is way nicer to program than excel interop.

Christian Sauer
  • 10,351
  • 10
  • 53
  • 85
  • but i need support 2003. epplus support 2007 excel – rwe Jan 17 '13 at 09:16
  • There are some other packages in the wild, please search stackoverflow for examples. Aspose cells could be good, but you have to pay for it. Using excel is probably a last ditch alternative... As a question: way do you have to support the old 2003 format? – Christian Sauer Jan 17 '13 at 10:30
  • it is my client requirement – rwe Jan 17 '13 at 11:25
0

To color any Row in Excel

oRange.get_Range("A1","X1").Interior.Color = System.Drawing.ColorTranslator.ToWin32(Color.Orange);

Hope it helps

Rohit
  • 10,056
  • 7
  • 50
  • 82
  • thanks for your response. but i need to know how to get proper rows and only color them. Is there any way to querying according to object. – rwe Jan 17 '13 at 07:57
0

I could not find any way to use Object property to map with row color in range writing way. I need to write cell by cell. but it is very slow. So i used creating html file(html table) and convert it to excel document. it is not slow also. Thank you very much for all replies

rwe
  • 177
  • 1
  • 1
  • 11
0

please refer this Export HTML Table to Excel using ASP.NET

Community
  • 1
  • 1
rwe
  • 177
  • 1
  • 1
  • 11