如何更改单元格样式与ExcelLibrary

如何更改单元格样式与ExcelLibrary

本文介绍了如何更改单元格样式与ExcelLibrary Excel文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人可以帮助我?
我想设置一个单元格背景和字体颜色,但我不知道我能做到这一点。
我试图让访问一个单元格样式,但我没有发现它。

Can anybody help me with ExcelLibrary?I'd like to set a cell background and font color, but I don't know how can I do it.I try to get access to a cell style, but I didn't found it.

任何人有什么想法?

推荐答案

我已经研究过这个库,为您和发现下列(警告 - 这是个坏消息!):

I've looked into this library for you and found the following (warning - it's bad news!):


  1. 有是没有发布的版本,允许访问单元格的颜色。

  1. There is no released version of ExcelLibrary that allows access to cell colours.

在未发行的源代码中有一个在新的<$ C一背景色属性$ C> CellStyle 类,但没有属性来表示前景色。

In the unreleased source code there is a BackColor property in the new CellStyle class, however there is no property to represent foreground colour.

背景色时,保存工作簿属性不会持续。它仅用于设置工作簿时装载的细胞的背景颜色

The BackColor property is not persisted when the workbook is saved. It is only used to set the background colour of a cell when the workbook is loaded.

如果使用的颜色是一个要求,然后使用(所推荐的@jamietre)。然后,您可以设置前景色和背景色是这样的:

If use of colours is a requirement then use NPOI (as recommended by @jamietre). You can then set foreground and background colours like this:

HSSFCellStyle style1 = hssfworkbook.CreateCellStyle();

// cell background
style1.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.BLUE.index;
style1.FillPattern = HSSFCellStyle.SOLID_FOREGROUND;

// font color
HSSFFont font1 = hssfworkbook.CreateFont();
font1.Color = NPOI.HSSF.Util.HSSFColor.YELLOW.index;
style1.SetFont(font1);

cell.CellStyle = style1;

这篇关于如何更改单元格样式与ExcelLibrary Excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 00:50