OPENXML spreadsheat另存为 [英] openxml spreadsheat save-as

查看:191
本文介绍了OPENXML spreadsheat另存为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的OpenXML的SDK 2.
编辑我删除某些行等
我想知道如何保存Spreadsheetdocument到另一个文件名的Excel电子表格2007

I have an Excel 2007 spreadsheet that I edit with the OpenXML SDK 2. I remove some rows etc. I would like to know how to save that Spreadsheetdocument to another filename.

推荐答案

据我所知,还有的方式来更改文件名没有内置,但由于编辑文件的一种方法是使用流,你可以很容易地给写了一个流的内容,当你想要的文件的名称:

To my knowledge there is no built in way to change the filename, but since one way to edit the file is to use streams you can easily give the name of the file you want when writing out the contents of a stream:

byte[] byteArray = File.ReadAllBytes("C:\\temp\\oldName.xltx");
using (MemoryStream stream = new MemoryStream())
{
    stream.Write(byteArray, 0, (int)byteArray.Length);
    using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
    {
       // Do work here
    }
    File.WriteAllBytes("C:\\temp\\newName.xlsx", stream.ToArray()); 
}

有其他的方式来更改名称为好,返回文件时,像在ASP.NET MVC的Web应用程序的用户,但是它取决于你正在尝试做的。

There are other ways to change the name as well, like when returning the file to a user in an ASP.NET MVC web application, but it depends on what you are trying to do.

这篇关于OPENXML spreadsheat另存为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆