-
-
Notifications
You must be signed in to change notification settings - Fork 359
Async implementation of freezing top row #684
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
Conversation
Hi @BaatenHannes, thanks for the PR. :) I think to prevent repeating the Freeze pane code for the Async versions we can do the following:
private string GetSheetViews()
{
// exit early if no style to write
if (_configuration.FreezeRowCount <= 0 && _configuration.FreezeColumnCount <= 0)
{
return string.Empty;
}
var sb = new StringBuilder();
// start sheetViews
sb.Append(WorksheetXml.StartSheetViews);
sb.Append(WorksheetXml.StartSheetView());
// Write panes
sb.Append(GetPanes());
// end sheetViews
sb.Append(WorksheetXml.EndSheetView);
sb.Append(WorksheetXml.EndSheetViews);
return sb.ToString();
}
private string GetPanes()
{
var sb = new StringBuilder();
string activePane;
if (_configuration.FreezeColumnCount > 0 && _configuration.FreezeRowCount > 0)
{
activePane = "bottomRight";
}
else if (_configuration.FreezeColumnCount > 0)
{
activePane = "topRight";
}
else
{
activePane = "bottomLeft";
}
sb.Append(
WorksheetXml.StartPane(
xSplit: _configuration.FreezeColumnCount > 0 ? _configuration.FreezeColumnCount : (int?)null,
ySplit: _configuration.FreezeRowCount > 0 ? _configuration.FreezeRowCount : (int?)null,
topLeftCell: ExcelOpenXmlUtils.ConvertXyToCell(
_configuration.FreezeColumnCount + 1,
_configuration.FreezeRowCount + 1
),
activePane: activePane,
state: "frozen"
)
);
// write pane selections
if (_configuration.FreezeColumnCount > 0 && _configuration.FreezeRowCount > 0)
{
// freeze row and column
/*
<selection pane="topRight" activeCell="B1" sqref="B1"/>
<selection pane="bottomLeft" activeCell="A3" sqref="A3"/>
<selection pane="bottomRight" activeCell="B3" sqref="B3"/>
*/
var cellTR = ExcelOpenXmlUtils.ConvertXyToCell(_configuration.FreezeColumnCount + 1, 1);
sb.Append(WorksheetXml.PaneSelection("topRight", cellTR, cellTR));
var cellBL = ExcelOpenXmlUtils.ConvertXyToCell(1, _configuration.FreezeRowCount + 1);
sb.Append(WorksheetXml.PaneSelection("bottomLeft", cellBL, cellBL));
var cellBR = ExcelOpenXmlUtils.ConvertXyToCell(_configuration.FreezeColumnCount + 1, _configuration.FreezeRowCount + 1);
sb.Append(WorksheetXml.PaneSelection("bottomRight", cellBR, cellBR));
}
else if (_configuration.FreezeColumnCount > 0)
{
// freeze column
/*
<selection pane="topRight" activeCell="A1" sqref="A1"/>
*/
var cellTR = ExcelOpenXmlUtils.ConvertXyToCell(_configuration.FreezeColumnCount, 1);
sb.Append(WorksheetXml.PaneSelection("topRight", cellTR, cellTR));
}
else
{
// freeze row
/*
<selection pane="bottomLeft"/>
*/
sb.Append(WorksheetXml.PaneSelection("bottomLeft", null, null));
}
return sb.ToString();
}
This will ensure that the sync and async writers are using the same code to build the panes. |
Hi @meld-cp, good point, didn't notice the DefaultOpenXml class. |
@BaatenHannes 👍👍👍 Merged, could we invite you to our team? |
I'm a bit busy at the moment. But thanks for the invite. |
See issue #678.
Added async implementation of PR #620 Freeze top row.