当前位置: 首页>>代码示例>>C#>>正文


C# Workbook.SuspendLayoutUpdate方法代码示例

本文整理汇总了C#中Workbook.SuspendLayoutUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.SuspendLayoutUpdate方法的具体用法?C# Workbook.SuspendLayoutUpdate怎么用?C# Workbook.SuspendLayoutUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Workbook的用法示例。


在下文中一共展示了Workbook.SuspendLayoutUpdate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Export

        public JsonResult Export(string model, string data, string format, string title)
        {
            Workbook workbook = new Workbook();
            workbook.History.IsEnabled = false;
            workbook.SuspendLayoutUpdate();

            workbook.Sheets.Add(SheetType.Worksheet);
            Worksheet worksheet = workbook.ActiveWorksheet;
            worksheet.Name = title;

            var modelObject = JsonConvert.DeserializeObject<IList<ColumnSettings>>(model);
            var dataObject = JsonConvert.DeserializeObject<dynamic>(data);
            var columnCount = modelObject.Count;

            for (int idx = 0; idx < columnCount; idx++)
            {
                var modelCol = modelObject[idx];
                string columnName = modelCol.Title ?? modelCol.Field;
                worksheet.Cells[0, idx].SetValue(columnName);
            }

            for (int rowIdx = 1; rowIdx < dataObject.Count; rowIdx++)
            {
                for (int colIdx = 0; colIdx < modelObject.Count; colIdx++)
                {
                    worksheet.Cells[rowIdx, colIdx].SetValue(dataObject[rowIdx - 1][modelObject[colIdx].Field].Value);
                }
            }

            if (format == "XLSX")
            {
                ColumnSelection columnSelection = worksheet.Columns[0, columnCount];
                columnSelection.AutoFitWidth();
            }

            workbook.ResumeLayoutUpdate();

            IWorkbookFormatProvider formatProvider = null;
            if (format == "XLSX")
            {
                formatProvider = new XlsxFormatProvider();
            }
            else
            {
                formatProvider = new CsvFormatProvider();
            }

            using (MemoryStream output = new MemoryStream())
            {
                formatProvider.Export(workbook, output);
                Session[title] = output.ToArray();
            }

            return Json(new { success = true }, JsonRequestBehavior.AllowGet);
        }
开发者ID:telerik,项目名称:kendo-examples-asp-net-mvc,代码行数:55,代码来源:HomeController.cs

示例2: GenerateWorkbook

        private static Workbook GenerateWorkbook(RadPivotGrid pivot)
        {
            var export = pivot.GenerateExport();

            Workbook workbook = new Workbook();
            workbook.History.IsEnabled = false;

            var worksheet = workbook.Worksheets.Add();

            workbook.SuspendLayoutUpdate();
            int rowCount = export.RowCount;
            int columnCount = export.ColumnCount;

            var allCells = worksheet.Cells[0, 0, rowCount - 1, columnCount - 1];
            allCells.SetFontFamily(new ThemableFontFamily(pivot.FontFamily));
            allCells.SetFontSize(12);
            allCells.SetFill(GenerateFill(pivot.Background));

            foreach (var cellInfo in export.Cells)
            {
                int rowStartIndex = cellInfo.Row;
                int rowEndIndex = rowStartIndex + cellInfo.RowSpan - 1;
                int columnStartIndex = cellInfo.Column;
                int columnEndIndex = columnStartIndex + cellInfo.ColumnSpan - 1;

                CellSelection cellSelection = worksheet.Cells[rowStartIndex, columnStartIndex];

                var value = cellInfo.Value;
                if (value != null)
                {
                    cellSelection.SetValue(Convert.ToString(value));
                    cellSelection.SetVerticalAlignment((Telerik.Windows.Documents.Spreadsheet.Model.RadVerticalAlignment) RadVerticalAlignment.Center);
                    cellSelection.SetHorizontalAlignment(GetHorizontalAlignment(cellInfo.TextAlignment));
                    int indent = cellInfo.Indent;
                    if (indent > 0)
                    {
                        cellSelection.SetIndent(indent);
                    }
                }

                cellSelection = worksheet.Cells[rowStartIndex, columnStartIndex, rowEndIndex, columnEndIndex];

                SetCellProperties(cellInfo, cellSelection);
            }

            for (int i = 0; i < columnCount; i++)
            {
                var columnSelection = worksheet.Columns[i];
                columnSelection.AutoFitWidth();

                //NOTE: workaround for incorrect autofit.
                var newWidth = worksheet.Columns[i].GetWidth().Value.Value + 15;
                columnSelection.SetWidth(new ColumnWidth(newWidth, false));
            }

            workbook.ResumeLayoutUpdate();
            return workbook;
        }
开发者ID:syatin003,项目名称:Wpf,代码行数:58,代码来源:ExportToCSVService.cs


注:本文中的Workbook.SuspendLayoutUpdate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。