[RESOLVED] Handling Excel application Using VB.Net
Hi everyone,
I am writing a code to save the data in Excel file.
I have done most of the things, but now I want to merge cells and color that cell.(BOth color background and font color)
For that I use XlRange.cell.font.color = 255
If I change that const 255 to any value no change occurs display brown color for each value.
Can anyone suggest me how to set color to individual cell and color codes and also how to merge cells.
Regards,
Mushtak
# 1 Re: [RESOLVED] Handling Excel application Using VB.Net
open your ms excel application. start recording a macro, then do whatever you want to the worksheet/workbook (ie merge cells, format cells, etc), and then turn it off when you're done. now, try to edit the macro, chadan! instant codes! :D
# 2 Re: [RESOLVED] Handling Excel application Using VB.Net
Hi,
I dont want to write macros in excel application.
I am writing code from vb.net ide. and i want to merge cell from code in vb.net and not in excel macros.
thanks
regards
mushtak
# 3 Re: [RESOLVED] Handling Excel application Using VB.Net
Mustaf, Thread1 merely suggested that you record a Macro in Excel, then whilst recording, do what you want, then stop recording. Now, after you've created the Macro, you can open the macro in Excel's VBA Editor by selecting:
Tools
Macro
Macros
Select the macro name in the list
Then, click on the Edit Button
This will open the VBA code behind the macro.
When I did it, it produced this :
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 18/08/2007 by HanneSThEGreaT
'
'
Range("A1:D2").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
End Sub
Voila, there's how you merge cells.
# 4 Re: [RESOLVED] Handling Excel application Using VB.Net
Hi
I solved the problem using following code
xlSheet as excel.WorkSheet
' to merge the cell from .net
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 10)).Merge()
'Center in merged cell
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1,10)).Cells.HorizontalAlignment = 3
From that i merge the excel cell from .net code
thanks
Mushtak :thumb: