[OpenXml] Generate excel in memory and dump to file
public static void GenerateExcelFromStream()
{
using (MemoryStream memoryStream = new MemoryStream()) {
using (SpreadsheetDocument document = SpreadsheetDocument.Create(memoryStream, SpreadsheetDocumentType.Workbook)) {
document.AddWorkbookPart();
document.WorkbookPart.Workbook = new Workbook(); document.WorkbookPart.AddNewPart<WorksheetPart>();
document.WorkbookPart.WorksheetParts.First().Worksheet = new Worksheet();
document.WorkbookPart.WorksheetParts.First().Worksheet.AppendChild(new SheetData()); Row row = new Row();
row.AppendChild<Cell>(new Cell() { CellValue = new CellValue("hahaasdfhkasddjjalsdkjflaksdjfladskjflj"), DataType = CellValues.String, CellReference = "A1" });
document.WorkbookPart.WorksheetParts.First().Worksheet.First().AppendChild(row);
document.WorkbookPart.WorksheetParts.First().Worksheet.Save(); document.WorkbookPart.Workbook.AppendChild(new Sheets());
document.WorkbookPart.Workbook.GetFirstChild<Sheets>().AppendChild(new Sheet() {
Id = document.WorkbookPart.GetIdOfPart(document.WorkbookPart.WorksheetParts.First()),
SheetId = ,
Name = "sheet1"
});
document.WorkbookPart.Workbook.Save();
} using (FileStream fileStream = File.Create("generateExcel.xlsx")) {
memoryStream.WriteTo(fileStream);
}
}
}
[OpenXml] Generate excel in memory and dump to file的更多相关文章
- Freebie - Utility Form: Generate Excel Report From SQL Query In Oracle Forms 6i And 11g
Sharing a form to generate Excel file report from SQL query in Oracle Forms. This form can be used i ...
- 使用OpenXML将Excel内容读取到DataTable中
前言:前面的几篇文章简单的介绍了如何使用OpenXML创建Excel文档.由于在平时的工作中需要经常使用到Excel的读写操作,简单的介绍下使用 OpenXML读取Excel中得数据.当然使用Open ...
- 一个用微软官方的OpenXml读写Excel 目前网上不太普及的方法。
新版本的xlsx是使用新的存储格式,貌似是处理过的XML. 传统的excel处理方法,我真的感觉像屎.用Oldeb不方便,用com组件要实际调用excel打开关闭,很容易出现死. 对于OpenXML我 ...
- C# - openxml 操作excel - '“System.IO.Packaging.Package”在未被引用的程序集中定义'
在 CodeProject中,有位网友写的一篇基于OpenXML SDK 2.0对excel(大数据量)进行操作,其中,运行的时候,有如下错误: 类型“System.IO.Packaging.Pack ...
- OpenXml操作Excel
要使用OpenXml首先要下载最新的Open XML Format SDK 2.0.具体的导入openxml的dll,去网上搜,很多 1.我个人写的XmlHelp类 using System; usi ...
- DocumentFormat.OpenXml read excel file
这里向大家介绍一种读取excel 数据的方法,用的是DoucmentFormat.OpenXml.dll 废话不多说,向大家展示一下在项目中处理过的方法,如果有任何疑问,随时联系我. using Do ...
- 使用DocumentFormat.OpenXml操作Excel文件.xlsx
1.开始 DocumentFormat.OpenXml是ms官方给一个操作office三大件新版文件格式(.xlsx,.docx,.pptx)的组件:特色是它定义了OpenXml所包含的所有对象(たぶ ...
- 使用OpenXml操作Excel,以下方法用于在添加列时修改Cell的CellReference属性。
以下方法实现了递增Excel中单元格的CellReference的功能,只支持两位字母. public static string CellReferenceIncrement(string cell ...
- 使用OpenXml把Excel中的数据导出到DataSet中
public class OpenXmlHelper { /// <summary> /// 读取Excel数据到DataSet中,默认读取所有Sheet中的数据 /// </sum ...
随机推荐
- PAT 1002
1002. A+B for Polynomials (25) This time, you are supposed to find A+B where A and B are two polynom ...
- PHP设计模式之策略模式
前提: 在软件开发中也常常遇到类似的情况,实现某一个功能有多种算法或者策略,我们可以根据环境或者条件的不同选择不同的算法或者策略来完成该功能.如查 找.排序等,一种常用的方法是硬编码(Hard Cod ...
- Node.js module.exports和exports的区别
require 用来加载代码,而 exports 和 module.exports 则用来导出代码,从接触node.js就不会它们两陌生,上代码: foo.js exports.a = functio ...
- 第二节:Maven的运行机制
Maven 的运行机制分为两个分别是生命周期和插件 首先我们来说说Maven的生命周期 1.1:生命周期是个个阶段组成的 1.2:Maven的生命周期是相互独立的,他们之间没有交集 1.3:阶段是有顺 ...
- Java作业代写
作业一 试用java编写一个九九乘法表并打印. 作业二: 设计两个人类与书类,并设置两者的关系,试用人去找书,书去找人,假如某人有一个儿子,它也有一本书,试用儿子去找书,书找儿子. 大作业 熟悉QQ农 ...
- thymleaf分支用法
<div th:switch="${user.role}"> <p th:case="'admin'">User is an admin ...
- MySQL数据库的存储结构
--把若干条sql语句封装起来,起个名字,叫做过程,也是没有返回值的函数 --把这个过程存储在数据库中->存储过程 --存储过程的创建过程 create procedure proceduceN ...
- xml使用系统整理
1. 认识xml 可扩展标记语言,一种用于标记电子文档使其具有结果性的标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 2. 和超文本标记语言区别 2.1 ...
- android手机操作SD的使用方法
写入SD卡 package com.example.openfileproject; import java.io.File; import java.io.FileInputStream; impo ...
- ansible安装(批量执行命令
rpm安装 下载epl源 : Download the latest epel-release rpm from:http://dl.fedoraproject.org/pub/epel/6/x86 ...