Skip to content

Commit

Permalink
more work on colors for fills, fonts and borders
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Aug 15, 2023
1 parent 62422c3 commit da83bf8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
40 changes: 36 additions & 4 deletions src/xlsb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ int styles_bin(std::string filePath, std::string outPath, bool debug) {
}

if (color[0] == 0x03) {
out << "<color theme=\"" << color[1] << "\" />" << std::endl;

double tint = 0.0;
if (color[2] != 0) tint = (double)color[2]/32767;

std::stringstream stream;
stream << std::setprecision(16) << tint;

out << "<color theme=\"" << color[1] << "\" tint=\"" << stream.str() << "\" />";
}

if (color[1])
Expand Down Expand Up @@ -278,8 +285,33 @@ int styles_bin(std::string filePath, std::string outPath, bool debug) {
if (fls == 18) out << "gray0625";
out << "\">" << std::endl;
// if FF000000 & FFFFFFFF they can be omitted
out << "<fgColor rgb=\"" << to_argb(fgColor[6], fgColor[3], fgColor[4], fgColor[5]) << std::dec << "\" />" << std::endl;
out << "<bgColor rgb=\"" << to_argb(bgColor[6], bgColor[3], bgColor[4], bgColor[5]) << std::dec << "\" />" << std::endl;

double bgtint = 0.0, fgtint = 0.0;
if (bgColor[2] != 0) bgtint = (double)bgColor[2]/32767;
if (fgColor[2] != 0) fgtint = (double)fgColor[2]/32767;

std::stringstream bgstream, fgstream;
bgstream << std::setprecision(16) << bgtint;
fgstream << std::setprecision(16) << fgtint;

if (fgColor[0] == 0x00)
out << "<fgColor auto=\"1\" />" << std::endl;
if (fgColor[0] == 0x01)
out << "<fgColor indexed=\"" << fgColor[1] << "\" />";
if (fgColor[0] == 0x02)
out << "<fgColor rgb=\"" << to_argb(fgColor[6], fgColor[3], fgColor[4], fgColor[5]) << "\" />";
if (fgColor[0] == 0x03)
out << "<fgColor theme=\"" << fgColor[1] << "\" tint=\"" << fgstream.str() << "\" />";

if (bgColor[0] == 0x00)
out << "<bgColor auto=\"1\" />" << std::endl;
if (bgColor[0] == 0x01)
out << "<bgColor indexed=\"" << bgColor[1] << "\" />";
if (bgColor[0] == 0x02)
out << "<bgColor rgb=\"" << to_argb(bgColor[6], bgColor[3], bgColor[4], bgColor[5]) << "\" />";
if (bgColor[0] == 0x03)
out << "<bgColor theme=\"" << bgColor[1] << "\" tint=\"" << fgstream.str() << "\" />";

out << "</patternFill>" << std::endl;
out << "</fill>" << std::endl;
} else {
Expand Down Expand Up @@ -2307,7 +2339,7 @@ int worksheet_bin(std::string filePath, bool chartsheet, std::string outPath, bo
out << "<col" << " min=\"" << colFirst << "\" max =\"" << colLast << "\"";

if (ixfe > 0)
out << " s=\"" << ixfe << "\"";
out << " style=\"" << ixfe << "\"";

out << " width=\"" << (double)coldx/256 << "\"";
if (fields->fHidden)
Expand Down
19 changes: 17 additions & 2 deletions src/xlsb_funs.h
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,23 @@ std::string brtBorder(std::string type, std::istream& sas, bool swapit) {

out << "<" << type << " style = \"" << as_border_style(dg) << "\"";
if (dg > 0) {
out << "><color hex=\"" << to_argb(color[6], color[3], color[4], color[5]) << "\" />";
out << "</" << type << ">" << std::endl;

double tint = 0.0;
if (color[2] != 0) tint = (double)color[2]/32767;

std::stringstream stream;
stream << std::setprecision(16) << tint;

if (color[0] == 0x00)
out << "><color auto=\"1\" />" << std::endl;
if (color[0] == 0x01)
out << "><color indexed=\"" << color[1] << "\" />";
if (color[0] == 0x02)
out << "><color hex=\"" << to_argb(color[6], color[3], color[4], color[5]) << "\" />";
if (color[0] == 0x03)
out << "><color theme=\"" << color[1] << "\" tint=\"" << stream.str() << "\" />";

out << "</" << type << ">" << std::endl;
} else {
out << "/>" << std::endl;
}
Expand Down

0 comments on commit da83bf8

Please sign in to comment.