【问题标题】:ASP NET CORE MVC - How to binding data to spreadsheetASP NET CORE MVC - 如何将数据绑定到电子表格
【发布时间】:2021-11-30 07:48:44
【问题描述】:

如何使用来自列表对象的工作表上的数据创建电子表格? 我使用 devexpress asp net core 创建电子表格。

这是我的控制器:

public ActionResult Overview(IFormFile document)
        {
            var model = new DocumentModel();
            if (document != null)
            {
                //SaveFile(document);
                var stream = new MemoryStream();
                document.CopyTo(stream);

                //Office File API
                var workBook = new Workbook();
                workBook.LoadDocument(stream);
                //preprocess the uploaded file using Spreadsheet Document API

                model.DocumentId = document.FileName;
                model.ContentAccessorByStream = stream;
            }

            return View("Overview", model);
        }

如何将列表传递给电子表格?

【问题讨论】:

    标签: c# asp.net-core devexpress spreadsheet


    【解决方案1】:

    您可以尝试将包含数据的列表导入工作表:

    // Import the list into the worksheet.
    // Data starts with the B3 cell.
    workbook.Worksheets[0].Import(yourList, 2, 1);
    

    ...或使用数据绑定:

    private void BindToRange(List<MyObject> dataSource, CellRange 
        bindingRange, Worksheet sheet) {
    
        // Specify the binding options.
        ExternalDataSourceOptions dsOptions = new ExternalDataSourceOptions();
        dsOptions.ImportHeaders = true;
        dsOptions.CellValueConverter = new MyObjectConverter();
        dsOptions.SkipHiddenRows = true;
    
        // Bind the data source to the worksheet range.
        WorksheetDataBinding sheetDataBinding = sheet.DataBindings.BindToDataSource(dataSource, bindingRange, dsOptions);
    
        // Adjust the column width.
        sheetDataBinding.Range.AutoFitColumns();
    }
    

    请参考以下文章了解更多信息:

    【讨论】:

      猜你喜欢
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      • 2023-02-10
      • 2012-03-25
      • 2019-07-10
      • 1970-01-01
      相关资源
      最近更新 更多