Implement styles#538
Conversation
|
Just a quick note to say that overall this looks good and I think it is going in the right direction. I'll give more detailed feedback early next week. For code comments you are already using correct sentence-case but could you also add a full stop/period at the end of each line. This makes it easier to change comments into documentation. It isn't a rule that has been adhered to in the existing code but I would like to improve that going forward. |
|
Man, i wish i discovered this pull early, i wanted to know if a cell is stricken or not. Sat whole day and edited the code myself. Came till adding if stricken or not from the styles. Learnt a lot from my experience though. |
|
Is the data and styles coming together? |
Data and Formats have always been processed separately (e.g. When I finish the base work, I'm going to look into optimizations:
|
|
i got it, even formulae were being used similarly. Was able to satisfy my requirement with Another doubt, why every item in the style is an option? hope i am not bothering you.😊 |
@azarmadr this is because the particular style may not exist for a given cell. |
|
@jmcnamara We're currently using this fork in production and it's working well. What do I need to do to get this merged with Calamine? Some things to discuss:
|
You should create a non-draft PR with all the WIP files and code removed. I will try to do a review on the current code.
Overall I think it is okay but I may have specific comments during review.
Copy the style of the Xlsx documentation:
https://docs.rs/calamine/latest/calamine/struct.Xlsx.html#method.merged_regions_by_sheet
That is always good. :-)
I think not.
Probably not but lets try get it right for Xlsx first. |
| @@ -0,0 +1,253 @@ | |||
| # Style Support in Calamine | |||
There was a problem hiding this comment.
Remove this files from the final PR or convert it to documentation.
| /// The cell value | ||
| pub value: Data, | ||
| /// The cell style | ||
| pub style: Option<Style>, |
There was a problem hiding this comment.
Strictly speaking the style is never optional in the Excel file formats. There is always an implicit 0 style that is the default and is defined in the theme.xml file. Note, I'm not necessarily saying that it shouldn't be an Option<>.
| self.style = None; | ||
| } | ||
|
|
||
| /// Check if the cell has style information |
There was a problem hiding this comment.
Again, an Excel cell will always have style information even if it is implicit for size reasons.
| let mut style = None; | ||
|
|
||
| // Extract style ID if present | ||
| if let Ok(Some(style_id_str)) = |
There was a problem hiding this comment.
Again, the style id is 0 and not None if not present.
| } | ||
|
|
||
| /// Get effective column width (custom or default) | ||
| pub fn get_effective_column_width(&self, column: u32) -> f64 { |
There was a problem hiding this comment.
This effective width is probably not the width that the user would expect and also may be dependent on the default font for the file.
See the following for the calculation in the other direction: https://github.com/jmcnamara/rust_xlsxwriter/blob/main/src/worksheet.rs#L19340-L19368
However, there may not be any simple way to return the correct value in all cases.
| } | ||
|
|
||
| /// Get effective row height (custom or default) | ||
| pub fn get_effective_row_height(&self, row: u32) -> f64 { |
There was a problem hiding this comment.
Same comment for row height although the height calculation is simpler.
| use crate::style::*; | ||
| use crate::XlsxError; | ||
|
|
||
| /// Get default Excel 2007+ theme color scheme (Office theme) |
There was a problem hiding this comment.
Avoid using /// for non-public non-doc comments. Also this is an example of where proper sentence punctuation should be applied.
|
First review done. Some general comments:
|
|
@ddimaria Any update on this? |
|
Finally back on this 😄 |
|
I've merged main into this branch, resolving conflicts and fixing tests. I also have a 1M cell style file being used in new benchmark tests (used criterion). I'm moving on to flamegraph and will start improvements based on the results. |
|
I just implemented RLE and other optimizations. I'll close this PR and open a new one tomorrow, and will squash all of my commits. The perf is a lot better now, and there is less of a memory footprint. |
|
I added support for Rich Text, which handles various formats within a single cell. This is how excel stores it: <si>
<r>
<rPr>
<b/> <!-- bold -->
<sz val="11"/>
<color rgb="FF0000FF"/>
<rFont val="Calibri"/>
</rPr>
<t>Bold blue text</t>
</r>
<r>
<rPr>
<i/> <!-- italic -->
<sz val="11"/>
<color rgb="FFFF0000"/>
</rPr>
<t> italic red text</t>
</r>
</si> |
Resolves merge conflicts in Cargo.toml (rstest version) and tests/test.rs (pivot table tests vs style tests — keep both). This merge adds: - Style struct with Font/Fill/Borders/Alignment/NumberFormat/Protection - styles.xml parser (src/xlsx/style_parser.rs) - worksheet_style() API returning row×col style grid - RLE-compressed StyleRange for memory efficiency Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
I noticed a bug in colors where tints weren't being handled. This is now implemented. |
|
@jmcnamara I need to implement conditional formatting and validations, is it OK to add them to this PR? |
|
@ddimaria This PR is already very large. It would be best to get this stabilized first (is it suitable for review now?). You can create other PRs that are dependent on this on. Conditional formatting and Data Validation should be separate PRs. |
That works for me. I just rebased my fork's commits onto upstream/master and squashed into a single commit. |
is this PR now ready for review and can be merge? 👀 |
@Erik1000 I believe it is, though some conflicts just popped up. Let me review those and CI and it will be ready to review/merge. |
b01bbe7 to
abca36f
Compare
|
@jmcnamara this PR is ready for review. I'm staring conditional formatting in another branch. |
Ok. Fix the |
|
@ddimaria will you submit a new PR or is there already an existing one? |
|
I'm back on this today. Will resolve conflicts and start a new PR |
|
PR moved to #653, it OK to close this one. |
Add style support for Calamine.
Basic api for getting styles
Here is the relevant structs so far: