小编Mat*_*ock的帖子

使用openxml将背景颜色应用于excel中的特定单元格

以下是我拥有的代码,在下面的最终方法中,我完成了所有操作。请忽略方法的返回类型,我后来改了。

public static byte[] CreateExcelDocument<T>(List<T> list, string filename)
        {
            DataSet ds = new DataSet();
            ds.Tables.Add(ListToDataTable(list));
            byte[] byteArray = CreateExcelDocumentAsStream(ds, filename);
            return byteArray;
        }
public static bool CreateExcelDocumentAsStream(DataSet ds, string filename, System.Web.HttpResponse Response)
        {
            try
            {
                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                using (SpreadsheetDocument document = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook, true))
                {
                    WriteExcelFile(ds, document);
                }
                stream.Flush();
                stream.Position = 0;

                Response.ClearContent();
                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "";

                //  NOTE: If you get an "HttpCacheability does not exist" error on the following line, make sure …
Run Code Online (Sandbox Code Playgroud)

.net c# excel openxml

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

.net ×1

c# ×1

excel ×1

openxml ×1