writing with different color in excel
-
Excel.Workbook theWorkbook = this.Excelobj.Workbooks.Open(strInputFileName, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,0, true,false,false); Excel.Sheets sheets = theWorkbook.Worksheets; Excel.Worksheet excelWorksheet = (Excel.Worksheet)sheets.get_Item(1); Excel.Range tempRange = (Excel.Range) excelWorksheet.get_Range("C1","IV1"); System.Array tempArray = (System.Array)tempRange.Cells.Value2; string[] exchangeData = ConvertToStringArray(tempArray); //Determining the Excel Cell data range int totalExcCount = exchangeData.Length; string remarkCellName = convIndexToCellName(totalExcCount+3); string lastExcCellName = convIndexToCellName(totalExcCount+2); //Creating a new column "Remarks" in the excel. Excel.Range remarkRange = (Excel.Range) excelWorksheet.get_Range(remarkCellName + "1",remarkCellName + "1"); string strRemark = "Remarks"; Object[] args1 = new Object[1]; args1[0] = strRemark; remarkRange.GetType().InvokeMember("Value",BindingFlags.SetProperty,null,remarkRange,args1); Now as above when writing in excel I want that I should be able to write "Remarks" with some different color say red how can i do that Thanks
Ankit Aneja "Nothing is impossible. The word itself says - I M possible"
-
Excel.Workbook theWorkbook = this.Excelobj.Workbooks.Open(strInputFileName, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,0, true,false,false); Excel.Sheets sheets = theWorkbook.Worksheets; Excel.Worksheet excelWorksheet = (Excel.Worksheet)sheets.get_Item(1); Excel.Range tempRange = (Excel.Range) excelWorksheet.get_Range("C1","IV1"); System.Array tempArray = (System.Array)tempRange.Cells.Value2; string[] exchangeData = ConvertToStringArray(tempArray); //Determining the Excel Cell data range int totalExcCount = exchangeData.Length; string remarkCellName = convIndexToCellName(totalExcCount+3); string lastExcCellName = convIndexToCellName(totalExcCount+2); //Creating a new column "Remarks" in the excel. Excel.Range remarkRange = (Excel.Range) excelWorksheet.get_Range(remarkCellName + "1",remarkCellName + "1"); string strRemark = "Remarks"; Object[] args1 = new Object[1]; args1[0] = strRemark; remarkRange.GetType().InvokeMember("Value",BindingFlags.SetProperty,null,remarkRange,args1); Now as above when writing in excel I want that I should be able to write "Remarks" with some different color say red how can i do that Thanks
Ankit Aneja "Nothing is impossible. The word itself says - I M possible"
-
Excel.Workbook theWorkbook = this.Excelobj.Workbooks.Open(strInputFileName, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,0, true,false,false); Excel.Sheets sheets = theWorkbook.Worksheets; Excel.Worksheet excelWorksheet = (Excel.Worksheet)sheets.get_Item(1); Excel.Range tempRange = (Excel.Range) excelWorksheet.get_Range("C1","IV1"); System.Array tempArray = (System.Array)tempRange.Cells.Value2; string[] exchangeData = ConvertToStringArray(tempArray); //Determining the Excel Cell data range int totalExcCount = exchangeData.Length; string remarkCellName = convIndexToCellName(totalExcCount+3); string lastExcCellName = convIndexToCellName(totalExcCount+2); //Creating a new column "Remarks" in the excel. Excel.Range remarkRange = (Excel.Range) excelWorksheet.get_Range(remarkCellName + "1",remarkCellName + "1"); string strRemark = "Remarks"; Object[] args1 = new Object[1]; args1[0] = strRemark; remarkRange.GetType().InvokeMember("Value",BindingFlags.SetProperty,null,remarkRange,args1); Now as above when writing in excel I want that I should be able to write "Remarks" with some different color say red how can i do that Thanks
Ankit Aneja "Nothing is impossible. The word itself says - I M possible"
Ankit, Here is the Solution: Call this line remarkRange.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); and this will set the Font color to RED. Manoj
-
Excel.Workbook theWorkbook = this.Excelobj.Workbooks.Open(strInputFileName, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,0, true,false,false); Excel.Sheets sheets = theWorkbook.Worksheets; Excel.Worksheet excelWorksheet = (Excel.Worksheet)sheets.get_Item(1); Excel.Range tempRange = (Excel.Range) excelWorksheet.get_Range("C1","IV1"); System.Array tempArray = (System.Array)tempRange.Cells.Value2; string[] exchangeData = ConvertToStringArray(tempArray); //Determining the Excel Cell data range int totalExcCount = exchangeData.Length; string remarkCellName = convIndexToCellName(totalExcCount+3); string lastExcCellName = convIndexToCellName(totalExcCount+2); //Creating a new column "Remarks" in the excel. Excel.Range remarkRange = (Excel.Range) excelWorksheet.get_Range(remarkCellName + "1",remarkCellName + "1"); string strRemark = "Remarks"; Object[] args1 = new Object[1]; args1[0] = strRemark; remarkRange.GetType().InvokeMember("Value",BindingFlags.SetProperty,null,remarkRange,args1); Now as above when writing in excel I want that I should be able to write "Remarks" with some different color say red how can i do that Thanks
Ankit Aneja "Nothing is impossible. The word itself says - I M possible"
To fill the color for One cell, ((Excel.Range)worksheet.Cells[row, column]).Interior.Color = ColorTranslator.ToOle(color) ; To fill the color for range. worksheet.get_Range("A1","A2").Interior.Color = ColorTranslator.ToOle(color); Hope to catch well!!! :doh: