创建xlsx文件

时间:2012-10-05 08:40:05

标签: c# .net excel xlsx

我基本上是在创建一个xlsx文件但是在使用该文件时遇到错误,如下所示。

  

System.IO.FileFormatException:存档文件的大小不能为0。

我尝试的方式。

string file = "c:\\DoneDone61.xlsx";

using(File.Create(file))
{

}

此外,我无法手动打开excel文件,因为它说文件已损坏。

提前感谢您的回答。

5 个答案:

答案 0 :(得分:4)

您认为“空白”的Excel文件不仅仅是一个没有数据的文件(这是您正在创建的文件)。您可以通过在Excel中手动创建文档然后在记事本中打开文档来自行查看。您会注意到它实际上有数据。该数据用于存储关于名为“Sheet1”,“Sheet2”和“Sheet3”的三个空纸张的信息。此外,还有一些标题信息,以便查看该文件的任何程序都知道它实际上是一个压缩文件(根据Excel文件格式)。因此,正如您所看到的,即使是一个非常空的Excel文件仍然包含一些数据。

如果您想使用C#创建一个空白的Excel文档,您有两个不错的选择:

  1. 使用一个库,该库允许您实际使用创建正确创建文件的Excel文档。查看Microsoft OpenXML SDKExcelPackage
  2. 之类的内容
  3. 创建一个空的Excel文档,将其存储在某个地方,当您想“创建”一个新的空Excel文档时,只需复制该文件即可。

答案 1 :(得分:1)

这一个......

using(File.Create(filePath))
{
}

...创建一个空文件。阅读:真空(=> 0字节)不是带有XLSX骨架的空XLSX:ZIP容器,文件头,样式定义,......

你到底想要什么?

修改 如果要创建空XLSX文件(例如“右键单击鼠标>新建>新建Microsoft Excel”),则必须使用此类模板,然后将其写入磁盘。

要实现这一点,您必须将此模板文件与您的应用程序一起部署,然后执行File.Copy(source, dest),或将其作为资源集成,并将资源内容写入磁盘。

答案 2 :(得分:1)

您需要使用的是Interop.Excel命名空间。这是msdn

的指南

答案 3 :(得分:0)

请使用此...有点hacky但是使用InterOp无法获得更好的方法

   public static void CreateEmptyXLSXFile(string FilePath)
    {
        FileStream MyStream = new FileStream(FilePath, FileMode.CreateNew,     FileAccess.ReadWrite);
        MyStream.Write(ExcelDocumentsInterOps.GetEmptyXSLXFileBytes(), 0, ExcelDocumentsInterOps.GetEmptyXSLXFileBytes().Length);
        MyStream.Flush();
        MyStream.Close();
        MyStream.Dispose();
        MyStream = null;
    }

    /// <summary>
    /// Returns the bytes for an empty xslx file
    /// </summary>
    /// <returns></returns>
    public static byte[] GetEmptyXSLXFileBytes()
    {
        string TheSting = "UEsDBBQABgAIAAAAIQBYVsaPYAEAABgFAAATANoBW0NvbnRlbnRfVHlwZXNdLnhtbCCi1gEooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMyUTU7DMBCF90jcIfIWJW6LhBBK2gU/S+iiHMDYk8aqY1set7S3Z5LQSqAQqYQFm0SRNe+9+WacfLGvTbKDgNrZgk2zCUvASqe0XRfsdfWU3rIEo7BKGGehYAdAtphfXuSrgwdMqNpiwaoY/R3nKCuoBWbOg6WT0oVaRPoMa+6F3Ig18NlkcsOlsxFsTGO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h4mfNtWyNglKfqSDfmyoRx528l3IXW3CBsqD57vQ7cfL8BPo6WyS89evxaGn5HHd9ScAAAD//wMAUEsBAi0AFAAGAAgAAAAhAFhWxo9gAQAAGAUAABMAAAAAAAAAAAAAAAAAAAAAAFtDb250ZW50X1R5cGVzXS54bWxQSwECLQAUAAYACAAAACEAtVUwI/UAAABMAgAACwAAAAAAAAAAAAAAAABrAwAAX3JlbHMvLnJlbHNQSwECLQAUAAYACAAAACEAu4FE2vAAAABHAwAAGgAAAAAAAAAAAAAAAABXBgAAeGwvX3JlbHMvd29ya2Jvb2sueG1sLnJlbHNQSwECLQAUAAYACAAAACEAL/AI5V0BAABwAgAADwAAAAAAAAAAAAAAAACHCAAAeGwvd29ya2Jvb2sueG1sUEsBAi0AFAAGAAgAAAAhAOmmJbiCBgAAUxsAABMAAAAAAAAAAAAAAAAAEQoAAHhsL3RoZW1lL3RoZW1lMS54bWxQSwECLQAUAAYACAAAACEAoIPErqMBAABkAwAADQAAAAAAAAAAAAAAAADEEAAAeGwvc3R5bGVzLnhtbFBLAQItABQABgAIAAAAIQC4SkstEwEAALcBAAAYAAAAAAAAAAAAAAAAAJISAAB4bC93b3Jrc2hlZXRzL3NoZWV0My54bWxQSwECLQAUAAYACAAAACEAuEpLLRMBAAC3AQAAGAAAAAAAAAAAAAAAAADbEwAAeGwvd29ya3NoZWV0cy9zaGVldDIueG1sUEsBAi0AFAAGAAgAAAAhAAdfONMeAQAAxwEAABgAAAAAAAAAAAAAAAAAJBUAAHhsL3dvcmtzaGVldHMvc2hlZXQxLnhtbFBLAQItABQABgAIAAAAIQAQFQ8XQQEAAF8CAAARAAAAAAAAAAAAAAAAAHgWAABkb2NQcm9wcy9jb3JlLnhtbFBLAQItABQABgAIAAAAIQCcPLtYiwEAADQDAAAQAAAAAAAAAAAAAAAAAPAYAABkb2NQcm9wcy9hcHAueG1sUEsFBgAAAAALAAsAygIAALEbAAAAAA==";
        return Convert.FromBase64String(TheSting);

    }

答案 4 :(得分:0)

在.NET中处理与电子表格相关的任务时,您可以使用名为SpreadsheetLight开源库来编写excel文件(特别是,如果您想在某些时候编写内容) )。

如果您希望将其添加为包via Nuget,则可以说:

  

Install-Package SpreadsheetLight

之后,经过GenerateReport() exmaple

// this one creates an empty workbook
using (SLDocument sl = new SLDocument())
{
    // sl.SetCellValue("B3", "I love ASP.NET MVC");
    sl.SaveAs("c:\\DoneDone61.xlsx");
}

另请参阅他们的tutorial了解更多有趣的内容。