Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. writing with different color in excel

writing with different color in excel

Scheduled Pinned Locked Moved C#
data-structuresquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ankit Aneja
    wrote on last edited by
    #1

    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"

    G M R 3 Replies Last reply
    0
    • A Ankit Aneja

      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"

      G Offline
      G Offline
      gauthee
      wrote on last edited by
      #2

      the get_range method itself has few poperties... Try out the Font property and thereby you can set the color for the font!!

      Gautham

      1 Reply Last reply
      0
      • A Ankit Aneja

        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"

        M Offline
        M Offline
        Manoj Kumar Rai
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • A Ankit Aneja

          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"

          R Offline
          R Offline
          robinhtoot
          wrote on last edited by
          #4

          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:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups