使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
来源:互联网 发布:淘宝价格趋势app 编辑:程序博客网 时间:2024/05/18 20:09
http://www.cnblogs.com/fmxyw/archive/2008/09/09/1287848.html
在用Excel作报表的时候,可能需要操作单元格的边框和填充颜色和纹理等操作,下面的代码说明如何设置选中的单元格的填充纹理和边框
try
{
ThisApplication = new Excel.Application();
ThisWorkbook = ThisApplication.Workbooks.Open("z://Book1.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
ThisApplication.DisplayAlerts = false;
xlSheet = (Excel.Worksheet)ThisWorkbook.Worksheets.get_Item(1);
Excel.Range range = xlSheet.get_Range("G4","H5");
range.Value = "123";
Excel.Style st = ThisWorkbook.Styles.Add("PropertyBorder", Type.Missing);
range.Interior.Pattern = Excel.XlPattern.xlPatternCrissCross;
range.Borders.Weight = 2;
range.Borders.get_Item(XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlContinuous;
range.Borders.get_Item(XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlContinuous;
range.Borders.get_Item(XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlContinuous;
range.Borders.get_Item(XlBordersIndex.xlDiagonalDown).LineStyle = Excel.XlLineStyle.xlLineStyleNone;
range.Borders.get_Item(XlBordersIndex.xlDiagonalUp).LineStyle = Excel.XlLineStyle.xlLineStyleNone;
range.Borders.get_Item(XlBordersIndex.xlInsideHorizontal).LineStyle = Excel.XlLineStyle.xlLineStyleNone;
range.Borders.get_Item(XlBordersIndex.xlInsideVertical).LineStyle = Excel.XlLineStyle.xlLineStyleNone;
range.Borders.get_Item(XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlLineStyle.xlDot;
range.Borders.get_Item(XlBordersIndex.xlEdgeLeft).Color = System.Drawing.ColorTranslator.ToOle(Color.Red);
ThisWorkbook.SaveAs("z://Book2.xls", Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
ThisWorkbook.Close(Type.Missing, Type.Missing, Type.Missing);
ThisApplication.Workbooks.Close();
ThisApplication.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisWorkbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisApplication);
ThisWorkbook = null;
ThisApplication = null;
GC.Collect();
this.Close();
}
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- 使用C#和Excel进行报表开发(四)-复制单元格
- 使用C#和Excel进行报表开发(七)-设置单元格的显示格式
- 使用C#和Excel进行报表开发(四)-复制单元格
- 使用C#和Excel进行报表开发(七)-设置单元格的显示格式
- 使用C#和Excel进行报表开发(四)-复制单元格
- 使用C#和Excel进行报表开发(七)-设置单元格的显示格式
- 使用C#和Excel进行报表开发(四)-复制单元格
- 使用C#和Excel进行报表开发(七)-设置单元格的显示格式
- 使用C#和Excel进行报表开发(四)-复制单元格
- Eresye制作的专家系统(玩具演示用)
- 转:VC++ 外壳扩展编程之windows右键菜单
- 使用C#和Excel进行报表开发(四)-复制单元格
- checkbox、group_concat和error
- bash下的方便快捷键
- 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色
- [转]typedef用法初探:
- 使用C#和Excel进行报表开发(六)-操作行和列
- 使用C#和Excel进行报表开发(七)-设置单元格的显示格式
- 网站的热门关键词分析
- 使用C#和Excel进行报表开发(八)-用程序绑定数据源
- 足坛十大最牛裁判:打边裁枪杀球员 红牌逐鹦鹉
- 人在职场,简历的编写
- IE8的滚动文字图片效果