本文整理汇总了C#中Workbook.BeginUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.BeginUpdate方法的具体用法?C# Workbook.BeginUpdate怎么用?C# Workbook.BeginUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workbook
的用法示例。
在下文中一共展示了Workbook.BeginUpdate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSpreadsheetReport
private static byte[] CreateSpreadsheetReport(IList<QueryReportDataGroup> reportData)
{
using (var workbook = new Workbook())
{
workbook.BeginUpdate();
var sheet = workbook.Worksheets.First();
sheet.Name = "Запросы";
var i = 0;
var j = 1;
foreach (var pair in reportData.First().Values) //шапка по горизонтали
{
var cell = sheet.Cells[i, j++];
cell.Value = pair.Key.title;
cell.FillColor = Colors.Accent;
cell.Font.Color = Color.White;
cell.Borders.LeftBorder.Color = Color.White;
cell.Borders.RightBorder.Color = Color.White;
cell.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
}
j = 0;
var grouped = reportData.GroupBy(t =>
{
if (t.GroupHead == t.Head)
return String.Empty;
return t.GroupHead;
});
foreach (var group in grouped) //группы по вертикали
{
j = 0;
i++;
var groupRange = sheet.Range.FromLTRB(0, i, reportData.First().Values.Count, i);
sheet.MergeCells(groupRange, MergeCellsMode.ByColumns);
groupRange.ExistingCells.First().Value = group.Key;
groupRange.Borders.BottomBorder.LineStyle = BorderLineStyle.Medium;
groupRange.Font.FontStyle = SpreadsheetFontStyle.Bold;
groupRange.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
foreach (var data in group) //данные по вертикали
{
j = 0;
i++;
sheet.Cells[i, j++].Value = data.Head;
foreach (var pair in data.Values) //запрос-значение по горизонтали
{
var cell = sheet.Cells[i, j++];
cell.Value = pair.Value.ToString();
cell.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
cell.NumberFormat = "@";
}
}
}
var reportRange = sheet.Range.FromLTRB(0, 0, reportData.First().Values.Count, i);
reportRange.Borders.SetAllBorders(Colors.Accent, BorderLineStyle.Thin);
reportRange.AutoFitColumns();
reportRange.ColumnWidth = reportRange.ColumnWidth * 0.5;
reportRange.Alignment.WrapText = true;
reportRange.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
reportRange.AutoFitRows();
workbook.EndUpdate();
using (var stream = new MemoryStream())
{
workbook.SaveDocument(stream, DocumentFormat.Xlsx);
return stream.ToArray();
}
}
}