你好,GcSpreadSheet1.SaveExcel("c:\zipfile\test.xlsx", GrapeCity.Windows.SpreadSheet.Data.ExcelFileFormat.XLSX, GrapeCity.Windows.SpreadSheet.Data.ExcelSaveFlags.SaveAsViewed)这个方法导出的excle是带有背景色但是我需要将格式数据保存到数据库,用这个方法保存到数据库的格式数据不可用,用gcSpreadSheet.SaveExcel(filePath, GrapeCity.Windows.SpreadSheet.Data.ExcelFileFormat.XLSX);保存到数据库的格式再打开也是没有背景色的。现在主要问题是导入excle后设置单元格背景色保存后(格式保存到数据库)再打开无背景色。以下是设置背景色的代码:
/// <summary>
/// 设置活动单元格背景
/// 【格式设置--切换背景色及填充颜色调用】
/// </summary>
/// <param name="_style"></param>
public void SetActivityCellBackground(Color _color)
{
try
{
m_SpreadSheet.gcSpreadSheet1.AutoRefresh = false;
m_SpreadSheet.gcSpreadSheet1.SuspendEvent();
int rowIndex = 0;
int columnIndex = 0;
string address = string.Empty;
// 循环单元格
Cell cell = null;
// List<GcSpreadCellInfo> gcList = new List<GcSpreadCellInfo>();
foreach (CellRange cellRange in m_SpreadSheet.gcSpreadSheet1.ActiveSheet.Selections)
{
CellRange range = GetActualRange(cellRange);
for (int i = 0; i < range.RowCount; i++)
{
for (int j = 0; j < range.ColumnCount; j++)
{
rowIndex = range.Row + i;
columnIndex = range.Column + j;
cell = m_SpreadSheet.gcSpreadSheet1.ActiveSheet[rowIndex, columnIndex];
cell.Background = new SolidColorBrush(_color);
CustomCellTagObj _tagObj = new CustomCellTagObj();
_tagObj = cell.Tag == null ? null : (CustomCellTagObj)cell.Tag;
if (_tagObj == null)
{
_tagObj = new CustomCellTagObj();
}
_tagObj.CellBackGround = cell.ActualBackground;//cell.Background;
cell.Tag = _tagObj;
}
}
}
m_SpreadSheet.gcSpreadSheet1.ResumeEvent();
m_SpreadSheet.gcSpreadSheet1.AutoRefresh = true;
}
catch (Exception ex)
{
throw new Exception("背景色设置失败!", ex);
}
}
|