在用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进行报表开发,生成统计图(Chart)
c#(excel)\使用C#和Excel进行报表开发(二)-操作统计图(Cha.doc
C#导出EXCEL如何设置单元格类型 - _NET技术 - C# 自己上网找的资料,没有经过测试,下载谨慎
使用C#和Excel进行报表开发(八)-用程序绑定数据
C#合并EXCEL单元格,C#纵向合并EXCEL相同内容单元格
C#操作EXCEL常见操作集合(行高,列宽,合并单元格,单元格边框线)
C#操作excel 打开-读取-修改-保存 winform入门操作 适合入门读者
C# 操作Excel单元格格式,具体的对操作Excel
//保存Excel的时候,不弹出是否保存的窗口直接进行保存 ==================================================================== using System; using System.Collections.Generic; using System.Text; using ...
基本的Excel操作,合并单元格,计算行高列管宽,冻结数据。。。相当全面的
C#读取Excel的代码,根据不同的需求做简单的更改即可,希望对您有帮助
文章介绍了使用C#设置EXCEL单元格格式
c# 操作Excel 单元格 数据库查询操作
C#读取Excel单元格内容并赋值给text一个简单demo C#读取Excel单元格内容并赋值给text一个简单demo C#读取Excel单元格内容并赋值给text一个简单demo
C#的,winform的,这是我自己写的一个c#操作excel的例子,其中包括数据操作,字体,格式,单元格等操作,还有一个生成柱状图的方法,所有的方法都在ExcelHelper.cs类里,点击Form1窗体里的按钮可以看到各种操作的...
C#对excel的操作C#对excel的操作C#对excel的操作C#对excel的操作C#对excel的操作C#对excel的操作C#对excel的操作C#对excel的操作C#对excel的操作C#对excel的操作
C 用Excel 高级报表