Tag: closedxml

在ClosedXml中“无法将主题颜色转换为颜色”

我试图使用ClosedXml读取Excel中单元格的填充背景颜色。 我正在使用此示例代码,并且能够无问题地读取Excel文档的内容,但无法将单元格的填充 BackgroundColor读作hex值。 我能够看到在BackgroundColor下定义的ThemeColor和ThemeTint属性,但是没有找到将它们转换为System.Color或hex值的方法。 这是我的代码: // Get all categories while (!categoryRow.Cell(coCategoryId).IsEmpty()) { IXLCell categoryName = categoryRow.Cell(coCategoryName); categories.Add(categoryName.GetString() + ” ” + XLColor.FromTheme(categoryName.Style.Fill.BackgroundColor.ThemeColor, categoryName.Style.Fill.BackgroundColor.ThemeTint).Color.ToHex()); categoryRow = categoryRow.RowBelow(); } 似乎XLColor.FromTheme方法总是抛出exception“无法将主题颜色转换为颜色”。 有没有人知道从ThemeColor和ThemeTint值获取System.Color的另一种方法? 更新: 我没有提到我已经尝试使用BackgroundColor的Color属性,遗憾的是这没有正确填充,如果你在调试器中查看它,那么你会看到这个属性抛出了我用方法XLColor获得的exception。 FromTheme 。 所以这肯定看起来像ClosedXml中的一个错误。 有谁知道解决方法?

如何使用closedxml向单元格添加符号?

我将数据插入虚拟excel。 我需要在文本之前将符号附加到某个单元格中。 请告诉我如何使用ClosedXML实现此目的。

使用ClosedXML将Gridview导出到Excel而不发出警告:您尝试打开的文件格式不同

我正在使用ASP.NET 4.5 Webform,我有一个Gridview(具有自定义TemplateField并从sqlDataSource获取数据) 我有这个事件将gridview内容导出到excel表,并且它完成了它的工作,除了创建的文件在用户打开它时发出警告(我理解,因为创建的文件不是实际的excel文件) : “您尝试打开的文件格式与文件扩展名指定的格式不同” protected void btnExport_Excel_Click(object sender, EventArgs e) { try { Response.Clear(); Response.Buffer = true; Response.AddHeader(“content-disposition”, “attachment;filename=GV.xls”); Response.Charset = “”; Response.ContentType = “application/ms-excel”; //Response.ContentType = “application/text”; Response.ContentEncoding = System.Text.Encoding.Unicode; Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble()); using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); //To Export all pages GridView4.AllowPaging = false; GridView4.AllowSorting = […]

使用ClosedXML从Excel文件中读取

我的Excel文件不在表格数据中。 我试图从excel文件中读取。 我的excel文件中的部分是表格式的。 我需要遍历第3到第20行,这些是表格并读取数据。 这是我的代码派对: string fileName = “C:\\Folder1\\Prev.xlsx”; var workbook = new XLWorkbook(fileName); var ws1 = workbook.Worksheet(1); 如何循环第3到第20行并读取第3,4,6,7,8列? 此外,如果一行为空,我如何确定,以便我可以跳过它而不读取每列具有给定行的值。

使用ClosedXML下载文件

所有 如何下载文件,以便用户看到它正在下载(如使用流?) 我目前正在使用ClosedXML,但如果我使用SaveAs方法,我必须提供一个硬编码的URL,如果我只是给它文件名,它不会自动下载到下载文件夹。 下面的方法效果很好,但是我必须创建自己的excel文件,该文件基于HTML,并且文件的增长方式太大了,当我使用ClosedXML时,文件的大小只有50%或更少。代码如下:但是,下载行为是我希望它的样子。 有没有办法可以转换下面的代码,所以我可以把我的’工作簿’作为一个对象,它只是下载这个工作簿? HttpContext.Current.Response.AppendHeader(“Content-Disposition”,”attachment;filename=Excel.xls”); HttpContext.Current.Response.Charset =”UTF-8″; HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = “application/ms-excel”; ctl.Page.EnableViewState =false; System.IO.StringWriter tw = new System.IO.StringWriter() ; System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw); ctl.RenderControl(hw); HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.End(); 谢谢