Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have this code below, in which I am trying to format cells with different
formats, is there a way of shortening this and maybe the change will make it run faster. These are sub heading that are suppose to be printed per produt info. Range rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" + LastRow.ToString()); rg.Font.Bold = true; rg.Font.Name = "Arial"; rg.Font.Size = 9; rg.Cells.RowHeight = 30; rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.Value2 = "string0"; LastRow++; LastRow++; rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" + LastRow.ToString()); rg.Font.Bold = true; rg.Font.Name = "Arial"; rg.Font.Size = 9; rg.Cells.RowHeight = 30; rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing); rg.WrapText = true; rg.Value2 = "string1"; rg = oWorkSheet.get_Range("B" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.ColumnWidth = 35; rg.Value2 = "string2"; rg = oWorkSheet.get_Range("C" + LastRow.ToString(), Type.Missing); rg.ColumnWidth = 35; rg.WrapText = false; rg.Value2 = "string3"; rg = oWorkSheet.get_Range("D" + LastRow.ToString(), Type.Missing); rg.WrapText = true; rg.Value2 = "string4"; rg = oWorkSheet.get_Range("E" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.Value2 = "string5"; rg = oWorkSheet.get_Range("F" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.ColumnWidth = 11; rg.Value2 = "string6"; rg = oWorkSheet.get_Range("G" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.ColumnWidth = 9; rg.Value2 = "string7"; |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Pamish
Can only suggest using a with statement to speed execution once you have set the range. e.g. with rg .Font.Bold = true; .Font.Name = "Arial"; .Font.Size = 9; .Cells.RowHeight = 30; end with P.S. What does LastRow++ do? -- Tony Green "Pamish" wrote: I have this code below, in which I am trying to format cells with different formats, is there a way of shortening this and maybe the change will make it run faster. These are sub heading that are suppose to be printed per produt info. Range rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" + LastRow.ToString()); rg.Font.Bold = true; rg.Font.Name = "Arial"; rg.Font.Size = 9; rg.Cells.RowHeight = 30; rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.Value2 = "string0"; LastRow++; LastRow++; rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" + LastRow.ToString()); rg.Font.Bold = true; rg.Font.Name = "Arial"; rg.Font.Size = 9; rg.Cells.RowHeight = 30; rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing); rg.WrapText = true; rg.Value2 = "string1"; rg = oWorkSheet.get_Range("B" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.ColumnWidth = 35; rg.Value2 = "string2"; rg = oWorkSheet.get_Range("C" + LastRow.ToString(), Type.Missing); rg.ColumnWidth = 35; rg.WrapText = false; rg.Value2 = "string3"; rg = oWorkSheet.get_Range("D" + LastRow.ToString(), Type.Missing); rg.WrapText = true; rg.Value2 = "string4"; rg = oWorkSheet.get_Range("E" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.Value2 = "string5"; rg = oWorkSheet.get_Range("F" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.ColumnWidth = 11; rg.Value2 = "string6"; rg = oWorkSheet.get_Range("G" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.ColumnWidth = 9; rg.Value2 = "string7"; |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am writing the program in c#, using Excel application to run my reports,
LastRow++ is telling it to go to the next row i.e if LastRow = 4, then after LastRow++, LastRow will be 5. The cells have got different formats ie. columnwidth, size, fontsize, etc. "ADG" wrote: Hi Pamish Can only suggest using a with statement to speed execution once you have set the range. e.g. with rg .Font.Bold = true; .Font.Name = "Arial"; .Font.Size = 9; .Cells.RowHeight = 30; end with P.S. What does LastRow++ do? -- Tony Green "Pamish" wrote: I have this code below, in which I am trying to format cells with different formats, is there a way of shortening this and maybe the change will make it run faster. These are sub heading that are suppose to be printed per produt info. Range rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" + LastRow.ToString()); rg.Font.Bold = true; rg.Font.Name = "Arial"; rg.Font.Size = 9; rg.Cells.RowHeight = 30; rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.Value2 = "string0"; LastRow++; LastRow++; rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" + LastRow.ToString()); rg.Font.Bold = true; rg.Font.Name = "Arial"; rg.Font.Size = 9; rg.Cells.RowHeight = 30; rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing); rg.WrapText = true; rg.Value2 = "string1"; rg = oWorkSheet.get_Range("B" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.ColumnWidth = 35; rg.Value2 = "string2"; rg = oWorkSheet.get_Range("C" + LastRow.ToString(), Type.Missing); rg.ColumnWidth = 35; rg.WrapText = false; rg.Value2 = "string3"; rg = oWorkSheet.get_Range("D" + LastRow.ToString(), Type.Missing); rg.WrapText = true; rg.Value2 = "string4"; rg = oWorkSheet.get_Range("E" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.Value2 = "string5"; rg = oWorkSheet.get_Range("F" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.ColumnWidth = 11; rg.Value2 = "string6"; rg = oWorkSheet.get_Range("G" + LastRow.ToString(), Type.Missing); rg.WrapText = false; rg.ColumnWidth = 9; rg.Value2 = "string7"; |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2007 format cells to date format | Excel Discussion (Misc queries) | |||
How to format cells in Excel 2007 (i.e. currency format)? | Excel Discussion (Misc queries) | |||
how do i format a cell based on format of a range of cells? | Excel Discussion (Misc queries) | |||
want format cells alignment not format cells font style | Excel Discussion (Misc queries) | |||
Cells won't convert to number format, even after format/cells/num. | Excel Discussion (Misc queries) |