您的位置:首页 > 编程语言 > ASP

aspose.cell 使用总结1 ~~实现单sheet和多sheet功能及表单属性设定

2014-11-29 15:28 477 查看
Workbook workbook = new Workbook();

workbook.Worksheets.Clear();

dt....

如果是多个sheet,使用for 循环生成:单个表单就不用了

for(int h=0;h<dt.Rows.Count;h++)

{

DataTable dthead = ......

Worksheet worksheet = workbook.Worksheets.Add(dt.Rows[h][""].ToString());//生成一个表单

worksheet.PageSetup.Zoom = 97;//打印时页面设置,缩放比例

worksheet.PageSetup.TopMargin = 0.5; //上边距为0.7

worksheet.PageSetup.BottomMargin =0.5; //下边距为0.7

worksheet.PageSetup.LeftMargin =0.5; //左边距为1.9

worksheet.PageSetup.RightMargin = 0.5; //右边距为1.9

worksheet.PageSetup.HeaderMargin = 0.5;//頁首邊距為0.6

worksheet.PageSetup.BottomMargin = 0.5;//頁尾邊距為0.6

Cells cell = worksheet.Cells;

string imageUrl = System.Web.HttpContext.Current.Server.MapPath("~/images/logoz.jpg");

worksheet.Pictures.Add(0, 1, imageUrl, 120, 70);//向某行某列加入图片

cell.Merge(0, 1, 3, 12);//合并行列

cell.SetRowHeight(0,16.5);//设置行高

cell.SetColumnWidthPixel(0,28);//设置列宽

cell[3, 1].Style.Font.Size = 20;//设置字体大小

cell[3, 1].Style.HorizontalAlignment = TextAlignmentType.Center;//数据水平居中

cell[7, 4].Style.IsTextWrapped = true;//数据自動換行

cell[10, 1].Style.Font.IsBold = true;//字体加粗

}

workbook.Save("222.xls", FileFormatType.Default, SaveType.OpenInExcel, System.Web.HttpContext.Current.Response);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐