1、添加命名空间Using Spire.Xls;Using System.Drawing;
2、初始化工作簿并加载文档Workbook workbook = new Workbook();workbook.LoadFromFile(@"C:\Users\Administrator\Desktop\test.xlsx", ExcelVersion.Version97to2003);Worksheet worksheet = workbook.Worksheets[0];Worksheet worksheet = workbook.Worksheets[0];
3、设置单元格背景颜色worksheet.Range["A1:C2"].Style.Color = Color.LightSeaGreen;worksheet.Range["A3:C4"].Style.Color = Color.LightYellow;worksheet.Range["A5:C19"].Style.Color = Color.SpringGreen;worksheet.Range["A20:C21"].Style.Color = Color.DeepSkyBlue;worksheet.Range["A22:C23"].Style.Color = Color.Yellow;
4、保存并预览文件workbook.SaveToFile("GradesRank.xls",ExcelVersion.Version97to2003;System.Diagnostics.Process.Start(workbook.FileName);