简体   繁体   English

使用C#excel OpenXML API从模板创建报告

[英]create a report from template using C# excel OpenXML API

I've been using Microsoft COM model to prepare reports but it is slow and fails if server does not have excel installed. 我一直在使用Microsoft COM模型来准备报告但是它很慢并且如果服务器没有安装excel则会失败。 So I am moving to using OpenXML for creating reports from a server process that does a ton of other things as well. 因此,我正在使用OpenXML从服务器进程创建报告,该进程还执行大量其他操作。

I've a template that contains named ranges for data that I need to change or extend, named charts, named chart series, named worksheets, etc. All my formatting is contained in excel file and all I do in my server side process is populate the file with data. 我有一个模板,其中包含我需要更改或扩展的数据的命名范围,命名图表,命名图表系列,命名工作表等。我的所有格式都包含在excel文件中,我在服务器端进程中所做的全部都是填充带有数据的文件。

These are the steps that I need to replicate using Excel OpenXML: 这些是我需要使用Excel OpenXML复制的步骤:

  1. Open an existing sheet and create a new sheet based on it. 打开现有工作表并基于它创建新工作表。
  2. Get the worksheet by worksheet name 按工作表名称获取工作表
  3. Get the Named Ranges in that worksheet. 获取该工作表中的命名范围。
  4. Populate the Named Ranges from data and extend the ranges if required based on data set. 从数据填充命名范围,并根据数据集扩展范围(如果需要)。
  5. Get Chart by Chart Name 按图表名称获取图表
  6. Get Chart Series by Series Title 按系列标题获取图表系列
  7. Set Chart series to the new range 将图表系列设置为新范围
  8. Export Chart to jpeg to be used in html. 将图表导出为jpeg以在html中使用。
  9. Save new File. 保存新文件。

Is it possible to do these steps in OpenXML cleanly? 是否可以干净地在OpenXML中执行这些步骤? Any examples will help me a lot. 任何例子都会对我有所帮助。 Or a light weight library that does this. 或者是一个轻量级的图书馆。 Some of these 3rd party libraries are too big and are more useful in creating new sheets from scratch. 其中一些第三方库太大,在从头开始创建新工作表时更有用。

Any help appreciated. 任何帮助赞赏。

AFAIK, with OpenXml you can do anything. AFAIK,使用OpenXml,你可以做任何事情。

I recommend a ClosedXml lib, it wraps OpenXML SDK and makes it easier to do your job. 我推荐一个ClosedXml lib,它包装OpenXML SDK并使你更容易完成工作。 Link contains samples and stuff. 链接包含样本和内容。 Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM