-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] basic style operations #10
Conversation
|
||
# copy entire attributes from original sheet to new sheet | ||
wb$worksheets[[id_new]]$sheet_data$row_attr <- | ||
wb$worksheets[[id_org]]$sheet_data$row_attr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about rows that are not present in the to_sheet
. Do we have to adjust the attributes list? Should test with some examples
I am planning to get rid of the I was looking for a certain functionality:
This is now possible. |
Ofc a few of the other functions should return, but for now the I simply removed them. A user should be able to modify a style or add a new style, but I want to do this without the struggle of the |
We have to understand the id handling of the styles xml, but that should not be impossible. Once that is done, all that is left are user functions to add style informations to the existing xml tables and add a value to the table in |
1b1c44c
to
d11f21e
Compare
* merged_cells cloneSheetStyle (bad name, cannot remember) * copy row, col, dimension and mergeCells
d11f21e
to
77866ed
Compare
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.cellformat?view=openxml-2.8.1 | ||
|
||
// openxml 2.8.1 | ||
Rcpp::CharacterVector nams = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently these fields are hard coded. I've looked them up in the doc above, but ofc they could be simply pushed down as a character vector.
auto n = df_xf.nrow(); | ||
Rcpp::CharacterVector z(n); | ||
|
||
Rcpp::CharacterVector xf_nams = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, hard coded fields.
characters matching sheet_data
std::ostringstream oss; worksheet.print(oss, " ", pugi::format_raw); z[itr](oss.str()); and something like this to write: xf.load_string()
fonts_df <- openxlsx2:::read_font(read_xml(wb$styles$fonts)) openxlsx2:::write_font(fonts_df)
> xlsx <- system.file("extdata", "oxlsx2_sheet.xlsx", package = "openxlsx2")
> wb <- loadWorkbook(xlsx)
>
> numFmts_df <- openxlsx2:::read_numfmt(read_xml(wb$styles$numFmts))
> numFmts_df
formatCode numFmtId
0 mmm\\-yy 164
1 #,##0, 165
2 #0 166
3 0.00\\ % 167
4 0\\ % 168
> read_xml(openxlsx2:::write_numfmt(numFmts_df))
<numFmt formatCode="mmm\-yy" numFmtId="164" />
<numFmt formatCode="#,##0," numFmtId="165" />
<numFmt formatCode="#0" numFmtId="166" />
<numFmt formatCode="0.00\ %" numFmtId="167" />
<numFmt formatCode="0\ %" numFmtId="168" /> |
Next TODO For border I assume attributes: |
library(openxlsx2)
xlsx <- system.file("extdata", "oxlsx2_sheet.xlsx", package = "openxlsx2")
wb <- loadWorkbook(xlsx)
x <- wb_to_df(wb, sheet = "SUM", detectDates = TRUE, dims = "B5:I16")
cloneWorksheet(wb, clonedSheet = "SUM", sheetName = "CLONE")
cleanSheet(wb, "CLONE",
numbers = TRUE,
characters = FALSE,
styles = FALSE,
merged_cells = FALSE)
# create some new data
x$V1_abs <- 1:11*1e6
x$V1_rel <- seq(0,1, length.out=11)
x$V2_abs <- rep(2, 11)
x$V2_rel <- rep(0.2, 11)
x$Dollar <- rep(NA, 11)
x$V3_abs <- rep(3, 11)
x$V3_rel <- rep(0.3, 11)
# TODO might want to add some some kind of merge styles option
writeData(wb, "CLONE", x, startCol = 2, startRow = 5, colNames = TRUE)
cloneSheetStyle(wb, "SUM", "CLONE")
saveWorkbook(wb, file = "/tmp/test.xlsx", overwrite = TRUE)
openXL("/tmp/test.xlsx") |
…ation to the wb$styles nodes to actually change styles
I think that much of the rcpp code can be simplified. Beyond that, there are many functions that can be further optimized. But now we have a few basic functions that can be used for implementation in userspace functions. |
A few basic functions to modify a sheet style
handle
styles.xml
Functions to convert styles.xml nodes to R dataframe objects and back to xml nodes. Future styles functions should use these functions:
new example functions to modify sheets
cloneSheetStyle
copy style information from one sheet to anothercleanWorksheet
remove data from sheet, could be numeric, character or styleThese are currently demo functions to show what is possible, but should motivate me to further look into the style functions.
example
summary
We now have basic functions in place that are capable of reading parts of styles.xml into different dataframe objects. When loading the workbook nothing is changed, the xml is simply imported as is into different nodes. If a modification is requested, the node can be converted into a dataframe. Once the modification is in placed, the dataframe can be converted into xml nodes and be assigned back.