Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Jan 06, 2016 3:49 pm

Im trying to format the color of a cell to the following RGB.

Code: Select all
cell.Style.Color = (Color.FromArgb(51, 155, 204))


The wrong color is being applied to the cell inside the document. The cell fill color in the excel document is RGB (51, 155, 155)

Any help on this issue would be appreciated

Thanks,

jkerb135
 
Posts: 9
Joined: Thu Sep 24, 2015 3:10 pm

Thu Jan 07, 2016 2:09 am

Hi,

Thanks for your posting and using our Spire.Xls.
Please set version of workbook to Version2007 and above version.
Code: Select all
Workbook workbook = new Workbook();
workbook.Version = ExcelVersion.Version2007;//or above Version
Worksheet sheet = workbook.Worksheets[0];
CellRange cell = sheet.Range["A1"];
cell.Style.Color = (Color.FromArgb(51, 155, 204));
workbook.SaveToFile("result.xlsx");


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Jan 08, 2016 7:32 am

Hi,

Have you tried above solution? Did it resolve your issue?
Thanks for your feedback.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Jan 12, 2016 4:37 pm

amy.zhao wrote:Hi,

Have you tried above solution? Did it resolve your issue?
Thanks for your feedback.

Best Regards,
Amy
E-iceblue support team


Yes this has resolved my issue.
I had the enum value in the
Code: Select all
worksheet.SaveToStream("filename.xlsx", ExcelVersion.Version2013);

when I added it to the worksheet as an initialization parameter it gave me the correct results.

Thank you,

jkerb135
 
Posts: 9
Joined: Thu Sep 24, 2015 3:10 pm

Wed Jan 13, 2016 2:43 am

Hi,

Thanks for your feedback.
Welcome to write to us again if you have further problems.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Sat May 15, 2021 8:55 pm

hi i am using xls i am trying to change specific cell's color . But i dont know how i am sending my code .
sheet.insertArray(oneDimensionalArray, 1, 1, true);



//Define a two-dimensional array

String[][] twoDimensionalArra = new String[][]{

{"Name", "Age", "Sex", "Dept."},

{"John", "25", "Male", "Development"},

{"Albert", "24", "Transgender", "Support"},

{"Amy", "26", "Female", "Sales"}

};



//Write the array to the worksheet from the specified cell

sheet.insertArray(sonuc, 1, 3);


sheet.getAllocatedRange().getStyle().setColor(Color.green);


//sheet.getCellRange("A1:E1").getStyle().setColor(Color.yellow);




//Save the file

wb.saveToFile("InsertArrays.xlsx", ExcelVersion.Version2016);

how can i change cell color of transgender to yellow for example . am i allowed to do that ?

ipproo111
 
Posts: 2
Joined: Sat May 15, 2021 6:43 pm

Sat May 15, 2021 9:44 pm

String[][] twoDimensionalArra = new String[][]{

{"Name", "Age", "Sex", "Dept."},

{"John", "25", "Male", "Development"},

{"Albert", "24", "Male", "Support"},

{"Amy", "26", "Female", "Sales"}

};
i made this multidimensional array and i can send to excel this array . but i cannot color cells . i mean i want to color john as blue and support as a yellow am i allowed to do that ?

ipproo111
 
Posts: 2
Joined: Sat May 15, 2021 6:43 pm

Mon May 17, 2021 7:43 am

Hello,

Thank you for your inquiry. Of course, our Spire.XLS could fulfill your requirement. Please refer to the following code. If there is any question, please feel free to write back.
Code: Select all
        Workbook workbook = new Workbook();
        Worksheet sheet = workbook.getWorksheets().get(0);

        String[][] twoDimensionalArra = new String[][]{
                {"Name","Age","Sex","Dept."},
                {"John","25","Male","Development"},
                {"Albert","24","Transgender","Support"},
                {"Amy","26","Female","Sales"}
        };
        sheet.insertArray(twoDimensionalArra,1,3);
        for (int i = sheet.getFirstRow(); i <= sheet.getLastRow(); i ++){
            for (int j = sheet.getFirstColumn(); j <= sheet.getLastColumn(); j ++){
                CellRange range = sheet.getRange().get(i,j);
                if (range.getValue().equals("John")){
                    range.getStyle().setColor(Color.BLUE);
                }
                if (range.getValue().equals("Support")){
                    range.getStyle().setColor(Color.YELLOW);
                }
            }
        }
        workbook.saveToFile("insertArrays.xlsx", ExcelVersion.Version2016);


Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1647
Joined: Wed Apr 07, 2021 2:50 am

Fri May 21, 2021 7:16 am

Hello,

Greetings from e-iceblue.
How is your issue going? Does the code we provide help you? Can you give us some feedback at your convenience? Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1647
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS