public void SetTitle(/*string TitString*/) //设置报表头
{
range = mySheet1.get_Range("A6", "D6");// 获取多个单元格
range.Merge(Missing.Value); // 合并单元格
range.Columns.AutoFit(); // 设置列宽为自动适应
range.NumberFormatLocal = "#,##0.00";// 设置单元格格式为货币格式
range.RowHeight = 20; // 设置行高
range.ColumnWidth = 20; // 设置列宽
range.Borders.LineStyle = 1; // 设置单元格边框
range.Font.Bold = true; // 加粗字体
range.Font.Size = 20; // 设置字体大小
range.Font.ColorIndex = 5; // 设置字体颜色
range.Interior.ColorIndex = 6; // 设置单元格背景色
// 设置单元格左边框加粗
//range.Borders[XlBordersIndex.xlEdgeLeft].Weight = XlBorderWeight.xlThick;
// 设置单元格右边框加粗
//range.Borders[XlBordersIndex.xlEdgeRight].Weight = XlBorderWeight.xlThick;
range.Value2 = "合并单元格";
}
public void SetContent() //设置内容
{
//在命名空间"Excel"中,还定义了一个类"Cell",这个类所代表的就是Excel表格中的一个单元格。通过给"Cell"赋值,从而实现往Excel表格中输入相应的数据
//Excel.Application excel = new Excel.Application () ;
//excel.Application.Workbooks.Add(true);
//excel.Cells[ 5 , 5 ] ="First Row First Column";
//excel.Cells[ 5 , 6 ] ="First Row Second Column";
//excel.Cells[ 6 , 5 ] ="Second Row First Column";
//excel.Cells[ 5 , 5 ] ="Second Row Second Column";
//excel.Visible = true ;
range = mySheet1.get_Range("A1", Missing.Value);// 获取单个单元格
range.Columns.AutoFit();
range.RowHeight = 20; // 设置行高
range.ColumnWidth = 20; // 设置列宽
range.Borders.LineStyle = 1; // 设置单元格边框
range.Font.Bold = true; // 加粗字体
range.Font.Size = 20; // 设置字体大小
range.Font.ColorIndex = 5; // 设置字体颜色
range.Interior.ColorIndex = 6; // 设置单元格背景色
//range.HorizontalAlignment = XlHAlign.xlHAlignCenter;// 设置单元格水平居中
//range.VerticalAlignment = XlVAlign.xlVAlignCenter;// 设置单元格垂直居中
range.Value2 = "设置行高和列宽";// 设置单元格的值
range = mySheet1.get_Range("B2", "D4");// 获取多个单元格
range.Merge(Missing.Value); // 合并单元格
range.Columns.AutoFit(); // 设置列宽为自动适应
range.NumberFormatLocal = "#,##0.00";// 设置单元格格式为货币格式
// 设置单元格左边框加粗
//range.Borders[XlBordersIndex.xlEdgeLeft].Weight = XlBorderWeight.xlThick;
// 设置单元格右边框加粗
//range.Borders[XlBordersIndex.xlEdgeRight].Weight = XlBorderWeight.xlThick;
range.Value2 = "合并单元格";
}
public void PrintSet () //打印设置
{
//mySheet1.PageSetup.PaperSize = mySheet1.XLPaperSize.xlPaperA4; // 设置页面大小为A4
//mySheet1.PageSetup.Orientation = XlPageOrientation.xlPortrait; // 设置垂直版面
mySheet1.PageSetup.HeaderMargin = 0.0; // 设置页眉边距
mySheet1.PageSetup.FooterMargin = 0.0; // 设置页脚边距
mySheet1.PageSetup.LeftMargin = myExcel.InchesToPoints(0.354330708661417); // 设置左边距
mySheet1.PageSetup.RightMargin = myExcel.InchesToPoints(0.354330708661417);// 设置右边距
mySheet1.PageSetup.TopMargin = myExcel.InchesToPoints(0.393700787401575); // 设置上边距
mySheet1.PageSetup.BottomMargin = myExcel.InchesToPoints(0.393700787401575);// 设置下边距
mySheet1.PageSetup.CenterHorizontally = true; // 设置水平居中
}
这里面的参数基本LZ要求的都有了..
最好是有一个思路可以把dgv显示的效果原封不动的放到excel里。
//不过要达到LZ这种要求,有点难度...
毕竟datagridviw与excel还是相差很多的....
{
range = mySheet1.get_Range("A6", "D6");// 获取多个单元格
range.Merge(Missing.Value); // 合并单元格
range.Columns.AutoFit(); // 设置列宽为自动适应
range.NumberFormatLocal = "#,##0.00";// 设置单元格格式为货币格式
range.RowHeight = 20; // 设置行高
range.ColumnWidth = 20; // 设置列宽
range.Borders.LineStyle = 1; // 设置单元格边框
range.Font.Bold = true; // 加粗字体
range.Font.Size = 20; // 设置字体大小
range.Font.ColorIndex = 5; // 设置字体颜色
range.Interior.ColorIndex = 6; // 设置单元格背景色
// 设置单元格左边框加粗
//range.Borders[XlBordersIndex.xlEdgeLeft].Weight = XlBorderWeight.xlThick;
// 设置单元格右边框加粗
//range.Borders[XlBordersIndex.xlEdgeRight].Weight = XlBorderWeight.xlThick;
range.Value2 = "合并单元格";
}
public void SetContent() //设置内容
{
//在命名空间"Excel"中,还定义了一个类"Cell",这个类所代表的就是Excel表格中的一个单元格。通过给"Cell"赋值,从而实现往Excel表格中输入相应的数据
//Excel.Application excel = new Excel.Application () ;
//excel.Application.Workbooks.Add(true);
//excel.Cells[ 5 , 5 ] ="First Row First Column";
//excel.Cells[ 5 , 6 ] ="First Row Second Column";
//excel.Cells[ 6 , 5 ] ="Second Row First Column";
//excel.Cells[ 5 , 5 ] ="Second Row Second Column";
//excel.Visible = true ;
range = mySheet1.get_Range("A1", Missing.Value);// 获取单个单元格
range.Columns.AutoFit();
range.RowHeight = 20; // 设置行高
range.ColumnWidth = 20; // 设置列宽
range.Borders.LineStyle = 1; // 设置单元格边框
range.Font.Bold = true; // 加粗字体
range.Font.Size = 20; // 设置字体大小
range.Font.ColorIndex = 5; // 设置字体颜色
range.Interior.ColorIndex = 6; // 设置单元格背景色
//range.HorizontalAlignment = XlHAlign.xlHAlignCenter;// 设置单元格水平居中
//range.VerticalAlignment = XlVAlign.xlVAlignCenter;// 设置单元格垂直居中
range.Value2 = "设置行高和列宽";// 设置单元格的值
range = mySheet1.get_Range("B2", "D4");// 获取多个单元格
range.Merge(Missing.Value); // 合并单元格
range.Columns.AutoFit(); // 设置列宽为自动适应
range.NumberFormatLocal = "#,##0.00";// 设置单元格格式为货币格式
// 设置单元格左边框加粗
//range.Borders[XlBordersIndex.xlEdgeLeft].Weight = XlBorderWeight.xlThick;
// 设置单元格右边框加粗
//range.Borders[XlBordersIndex.xlEdgeRight].Weight = XlBorderWeight.xlThick;
range.Value2 = "合并单元格";
}
public void PrintSet () //打印设置
{
//mySheet1.PageSetup.PaperSize = mySheet1.XLPaperSize.xlPaperA4; // 设置页面大小为A4
//mySheet1.PageSetup.Orientation = XlPageOrientation.xlPortrait; // 设置垂直版面
mySheet1.PageSetup.HeaderMargin = 0.0; // 设置页眉边距
mySheet1.PageSetup.FooterMargin = 0.0; // 设置页脚边距
mySheet1.PageSetup.LeftMargin = myExcel.InchesToPoints(0.354330708661417); // 设置左边距
mySheet1.PageSetup.RightMargin = myExcel.InchesToPoints(0.354330708661417);// 设置右边距
mySheet1.PageSetup.TopMargin = myExcel.InchesToPoints(0.393700787401575); // 设置上边距
mySheet1.PageSetup.BottomMargin = myExcel.InchesToPoints(0.393700787401575);// 设置下边距
mySheet1.PageSetup.CenterHorizontally = true; // 设置水平居中
}
这里面的参数基本LZ要求的都有了..
最好是有一个思路可以把dgv显示的效果原封不动的放到excel里。
//不过要达到LZ这种要求,有点难度...
毕竟datagridviw与excel还是相差很多的....