MortalreminderPT / edit-xlsx

A quick and easy-to-use Rust library for Excel file editing.
https://crates.io/crates/edit-xlsx
16 stars 4 forks source link

Read cell text-color, foreground, background color #8

Closed mschnell1 closed 3 months ago

mschnell1 commented 3 months ago

OK, I see the cell background color(s) via get_background() . ( I don't know what bg_color is and it comes as an index. I do hope I don't need it :) )

But In fact I do need the text color (which would be the "foreground color" in a converted format).

Any hints ?

Edit: I found that I can get the text color when I make FormatFont::color public in fonts.rs. This sometimes is a Theme color which I do not understand yet.

Thanks again !

MortalreminderPT commented 3 months ago

Basically, index is an expression of the color that appears in Excel 2007, and you can see its corresponding RGB expression in the official documentation, and theme is also an expression of color but it is determined by the theme of excel.

mschnell1 commented 3 months ago

(using the said "FormatFont::color pub" hack) I seem to be able to do an ADOC converter as intended. If I succeed you might be inclined to use it as an example....

MortalreminderPT commented 3 months ago

(using the said "FormatFont::color pub" hack) I seem to be able to do an ADOC converter as intended. If I succeed you might be inclined to use it as an example....

That's sounds amazing, I'm looking forward to your artifact!😀

mschnell1 commented 3 months ago

👍 I cloned the to_col()function into my code. as get_columns_with_format() returns a range of columns as a string.

To help to create an accessible vector of column width, I in fact did this function to handle the output of get_columns_with_format() :

fn decode_col_range(column_range: &str) -> RangeInclusive<u32> {
    let mut nn = column_range.split(':');
    let nl = nn.next();
    let nl = nl.unwrap();
    let cl = to_col(nl);
    let nh = nn.next();
    let nh = nh.unwrap();
    let ch = to_col(nh);
    cl - 1..=ch - 1
}

Is there a better way (planned) ?

MortalreminderPT commented 3 months ago

I can't find a better way to do this, at least in terms of execution efficiency. But I don't see the need to add this tiny function to the project. If more people have similar needs, I will reconsider it...

MortalreminderPT commented 3 months ago

In fact, the project has a similar Trait for tuples and strings. But I think exposing this feature would bother users by seeing them when they don't have to.

mschnell1 commented 3 months ago

OK, when publishing my example, anybody might copy the code. (nonetheless: is there any way to use the to_col() function in user code ? It is as method rather than a "free" function and hence might or might not accessible by appropriate programming...)

mschnell1 commented 3 months ago

In fact the text color in principle can be per character as well in Excel as in ADOC. I don't think that I would like to consider this, but implement some method to set the text color in a complete cell.

mschnell1 commented 3 months ago

I just got the thought that attributes like bold, italic and underline also might be considered ....

Thanks for listening...

MortalreminderPT commented 3 months ago

I just got the thought that attributes like bold, italic and underline also might be considered ....

Thanks for listening...

That's a very nice suggestion, would you like to open a new issue for it? I'll consider the possibility of implementing in the future (if energy is allowed)

MortalreminderPT commented 3 months ago

OK, when publishing my example, anybody might copy the code. (nonetheless: is there any way to use the to_col() function in user code ? It is as method rather than a "free" function and hence might or might not accessible by appropriate programming...)

In fact, it's just a matter of decimal conversion, and I'd prefer that users can implement it themselves because I want this crate feature to be as simple as possible. I may reconsider it if more people want it ....

MortalreminderPT commented 3 months ago

The problem seems to be solved, so I'm closing this issue. if you still encounter problems in your project, don't hesitate to open a new issue. I'd really appreciate it if you are willing to open your source code either in your repository or in edit-xlsx example(or both) after finishing the project, you can submit a pull request to merge the code. If you find this troublesome, you can also open a new issue and I will check your code in your repository and include it as my examples (perhaps with modifications)

mschnell1 commented 2 months ago

I created an issue for doing the example, but I don't know to create a pull request for this (in "development" I can't click "create branch")

mschnell1 commented 2 months ago

@MortalreminderPT I am rather happy with the xlsx->adoc converter program I did using this library. The resulting adoc files (asciidoc text with converted tables embedded) can even be converted to PDF using asciidoctor-pdf with respectable results including text and background coloring (after the theme file for the conversion was appropriately enhanced) One issue that I can't seem to eliminate is that with some examples the xlsx uses Themes for colors. I have no idea how to convert those to RGB so that I can select appropriate adoc color names. In by examples I see Theme ids 0 and 1 and tint values -1.0, 0.0 and 1.0 . As a workaround I currently use a wild guess.

MortalreminderPT commented 2 months ago

@MortalreminderPT I am rather happy with the xlsx->adoc converter program I did using this library. The resulting adoc files (asciidoc text with converted tables embedded) can even be converted to PDF using asciidoctor-pdf with respectable results including text and background coloring (after the theme file for the conversion was appropriately enhanced) One issue that I can't seem to eliminate is that with some examples the xlsx uses Themes for colors. I have no idea how to convert those to RGB so that I can select appropriate adoc color names. In by examples I see Theme ids 0 and 1 and tint values -1.0, 0.0 and 1.0 . As a workaround I currently use a wild guess.

Yeah, guess is a good method convert theme colors. Actually, theme colors are decided by the theme of Excel. For example, if you have a dark mode of xlsx, maybe the background color will be black and fontcolor will be white. I don't have a plan to offer a concrete method to finish the convert because it is not a simple function. Nevertheless, it is colors you guessed most of times.

mschnell1 commented 2 months ago

I in fact have no idea what "the theme of Excel" even is. Hence guessing is really difficult. Has this to do with way of selecting a color from the picking dialogue ?
In my examples Theme seems to be (sometimes) used when selecting black or white as a foreground or background color.