Aspose.Cells.dll的用法

  1  public void OutExcel()
  2         {
  3             #region
  4             WorkbookDesigner designer = new WorkbookDesigner();
  5             Worksheet sheet = designer.Workbook.Worksheets[0];
  6             Workbook book = designer.Workbook;
  7
  8             Aspose.Cells.Style style1 = book.Styles[book.Styles.Add()];
  9             style1.Font.Name = "黑体";//文字字体
 10             style1.Font.Size = 16;//文字大小
 11
 12             Aspose.Cells.Style style2 = book.Styles[book.Styles.Add()];
 13             style2.HorizontalAlignment = TextAlignmentType.Center;
 14             style2.Font.Name = "宋体";//文字字体
 15             style2.Font.IsBold = true;//粗体
 16             style2.Font.Size = 18;//文字大小
 17
 18             style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
 19             style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
 20             style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
 21             style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
 22             style2.Borders[BorderType.TopBorder].Color = Color.Black;
 23             style2.Borders[BorderType.BottomBorder].Color = Color.Black;
 24             style2.Borders[BorderType.LeftBorder].Color = Color.Black;
 25             style2.Borders[BorderType.RightBorder].Color = Color.Black;
 26
 27
 28
 29             Aspose.Cells.Style style3 = book.Styles[book.Styles.Add()];
 30             style3.HorizontalAlignment = TextAlignmentType.Center;
 31             style3.Font.Name = "宋体";//文字字体
 32             style3.Font.Size = 15;//文字大小
 33             style2.Font.IsBold = true;//粗体
 34
 35
 36             Aspose.Cells.Style style4 = book.Styles[book.Styles.Add()];
 37             style4.HorizontalAlignment = TextAlignmentType.Center;
 38             // style4.Font.Name = "黑体";//文字字体 "Arial Rounded MT Bold";//
 39             style4.Font.Size = 11;//文字大小
 40
 41             Aspose.Cells.Style style5 = book.Styles[book.Styles.Add()];
 42             style5.HorizontalAlignment = TextAlignmentType.Center;
 43             style5.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
 44             style5.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
 45             style5.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
 46             style5.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
 47             style5.Borders[BorderType.TopBorder].Color = Color.Black;
 48             style5.Borders[BorderType.BottomBorder].Color = Color.Black;
 49             style5.Borders[BorderType.LeftBorder].Color = Color.Black;
 50             style5.Borders[BorderType.RightBorder].Color = Color.Black;
 51
 52             //Aspose.Cells.Style style6 = book.Styles[book.Styles.Add()];
 53             //style6.ForegroundColor = Color.FromArgb(153, 204, 0);//设置背景色//#DCE6F1
 54             //style6.Pattern = Aspose.Cells.BackgroundType.Solid;
 55
 56             Aspose.Cells.Style style7 = book.Styles[book.Styles.Add()];
 57             style7.HorizontalAlignment = TextAlignmentType.Center;
 58             style7.Font.Name = "黑体";//文字字体
 59             style7.Font.Size = 11;//文字大小
 60
 61             var c21 = sheet.Cells[1, 0];
 62             c21.PutValue("点位");
 63             c21.SetStyle(style1);
 64
 65             var mm=sheet.Cells[7,1];
 66             mm.PutValue("中国1");
 67             mm.SetStyle(style1);
 68
 69             var nn = sheet.Cells[7, 2];
 70             nn.PutValue("中国2");
 71             nn.SetStyle(style1);
 72
 73             Range ranget1 = sheet.Cells.CreateRange(7, 1, 1, 2);
 74             ranget1.Merge();
 75             ranget1.RowHeight = 20;
 76
 77             Cells cells = sheet.Cells;
 78             cells.SetColumnWidth(1, 30);//设置列宽
 79
 80
 81             var c22 = sheet.Cells[1, 1];
 82             c22.PutValue("类型");
 83             c22.SetStyle(style1);
 84
 85
 86             for (int i = 0; i < 31; i++)
 87             {
 88                 var c23 = sheet.Cells[1, i + 2];
 89                 c23.PutValue(i + 1);
 90
 91                 c23.SetStyle(style1);
 92             }
 93             sheet.Cells[1, 33].PutValue("最小值"); sheet.Cells[1, 33].SetStyle(style1);
 94             sheet.Cells[1, 34].PutValue("最大值"); sheet.Cells[1, 34].SetStyle(style1);
 95             sheet.Cells[1, 35].PutValue("平均值"); sheet.Cells[1, 35].SetStyle(style1);
 96
 97             string year = "";
 98             string month = "";
 99             int rowcount = 0;
100
101
102
103             //添加样式
104             //sheet.Cells[m + t + 1, 33].SetStyle(style4);
105             //sheet.Cells[m + t + 1, 34].SetStyle(style4);
106             //sheet.Cells[m + t + 1, 35].SetStyle(style4);
107             //Range ranget = sheet.Cells.CreateRange(t + k + k, 0, 2, 1);//从第几行第几列到结束行结束列
108             //ranget.Merge(); //合并单元格
109
110
111             Range range5 = sheet.Cells.CreateRange(0, 0, rowcount * 2 + 2, 36);
112             Aspose.Cells.StyleFlag borderStyle = new Aspose.Cells.StyleFlag();
113             borderStyle.Borders = true; //启用Borders样式
114             borderStyle.HorizontalAlignment = true; //启用水平对齐样式
115             borderStyle.Font = false;//不使用配置的字体样式
116             range5.ApplyStyle(style5, borderStyle);
117
118
119
120             var c11 = sheet.Cells[0, 0];
121             string BiaoTi = "**监测有限公司" + year + "年" + month + "月水质监测结果汇总表";
122             c11.PutValue(BiaoTi);
123             c11.SetStyle(style2);
124
125             Range range = sheet.Cells.CreateRange(0, 0, 1, 36);
126             // Cell cell = range[0, 0];
127             range.Merge(); //合并单元格
128             range.RowHeight = 28;
129
130             Range range2 = sheet.Cells.CreateRange(2, 1, rowcount * 2 + 2, 36);
131             range2.RowHeight = 15;//设置行高
132
133             Range range3 = sheet.Cells.CreateRange(1, 0, 2, 36);
134             range3.RowHeight = 17;//设置行高
135
136
137             string XFilename = HttpUtility.UrlEncode("**环境" + year + "年" + month + "月水质监测汇总表.xls", Encoding.UTF8).ToString();
138             Aspose.Cells.SaveOptions ss = new XlsSaveOptions(SaveFormat.Excel97To2003);
139
140             designer.Workbook.Save(this.Response, XFilename, ContentDisposition.Attachment, ss);
141             #endregion
142         }

 1  public static class SqlHelper
 2     {
 3         private static readonly string conStr = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
 4
 5         public static int ExecuteNonQuery(string sql, CommandType cmdType, params SqlParameter[] pms)
 6         {
 7             using (SqlConnection con = new SqlConnection(conStr))
 8             {
 9                 using (SqlCommand cmd = new SqlCommand(sql, con))
10                 {
11                     cmd.CommandType = cmdType;
12                     if (pms != null)
13                     {
14                         cmd.Parameters.AddRange(pms);
15                     }
16                     con.Open();
17                     return cmd.ExecuteNonQuery();
18                 }
19             }
20         }
21
22         public static object ExecuteScalar(string sql, CommandType cmdType, params SqlParameter[] pms)
23         {
24             using (SqlConnection con = new SqlConnection(conStr))
25             {
26                 using (SqlCommand cmd = new SqlCommand(sql, con))
27                 {
28                     cmd.CommandType = cmdType;
29                     if (pms != null)
30                     {
31                         cmd.Parameters.AddRange(pms);
32                     }
33                     con.Open();
34                     return cmd.ExecuteScalar();
35                 }
36             }
37         }
38
39
40         public static SqlDataReader ExecuteReader(string sql, CommandType cmdType, params SqlParameter[] pms)
41         {
42             SqlConnection con = new SqlConnection(conStr);
43             try
44             {
45                 using (SqlCommand cmd = new SqlCommand(sql, con))
46                 {
47                     cmd.CommandType = cmdType;
48                     if (pms != null)
49                     {
50                         cmd.Parameters.AddRange(pms);
51                     }
52                     con.Open();
53                     SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
54                     return reader;
55                 }
56             }
57             catch
58             {
59                 con.Dispose();
60                 throw;
61             }
62         }
63
64
65         public static DataTable ExecuteDataTable(string sql, CommandType cmdType, params SqlParameter[] pms)
66         {
67             using (SqlDataAdapter sda = new SqlDataAdapter(sql, conStr))
68             {
69                 DataTable dt = new DataTable();
70
71                 sda.SelectCommand.CommandType = cmdType;
72                 if (pms != null)
73                 {
74                     sda.SelectCommand.Parameters.AddRange(pms);
75                 }
76                 sda.Fill(dt);
77                 return dt;
78             }
79         }
80     }

时间: 2024-10-01 22:12:31

Aspose.Cells.dll的用法的相关文章

C# 利用Aspose.Cells .dll将本地excel文档转化成pdf(完美破解版 无水印 无中文乱码)

Aspose.Cells .dll下载  http://pan.baidu.com/s/1slRENLF并引用 C#代码 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Wind

Aspose.Cells.dll引用导入导出Excel

Aspose.Cells 导入导出EXCEL 文章出处:http://hi.baidu.com/leilongbing/item/c11467e1819e5417595dd8c1 修改样式       Workbook workbook = new Workbook(); //工作簿 Worksheet sheet = workbook.Worksheets[0]; //工作表 Cells cells = sheet.Cells;//单元格 //样式2 Aspose.Cells.Style st

C# WinForm 导出导入Excel/Doc [使用Aspose.Cells.dll]

参考地址:http://blog.csdn.net/az44yao/article/details/7656074 private void DatatableToExcel(DataTable dgv, string Title) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Execl files (*.xls)|*.xls"; dlg.CheckFileExists = false; dlg.CheckPat

根据路径获得文件名以及Aspose.Cells.dll操作office(主要是excel)

string result = Regex.Match(str,@"[^\\]+$").Value;//正则表达式 this.listBox1.Items.Add(Path.GetFileName(str) + " ");//方法 //读取Excel中数据 到datatable Workbook workbook = new Workbook(str);//str是excel路径 Worksheet worksheet = workbook.Worksheets[0

在ASP.NET MVC中利用Aspose.cells 将查询出的数据导出为excel,并在浏览器中下载。

正题前的唠叨 本人是才出来工作不久的小白菜一颗,技术很一般,总是会有遇到一些很简单的问题却不知道怎么做,这些问题可能是之前解决过的.发现这个问题,想着提升一下自己的技术水平,将一些学的新的'好'东西记录下来,一是加深印象:二是以后可以作为参考:三是希望博友们可以提出不足和可以优化的地方,一起讨论. 这个是我去一家公司没多久,让我做的小功能,主要是导出excel并在浏览器下载下来. 但是会有不同的细微的需求差别. 第一次发博客,有描述不清楚的地方还请见谅,希望各位多多指点. 进入正题 简单的需求描

Aspose.Cells导出excel

利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public static bool DataTableToExcel2(DataTable datatable, string filepath, out string error) { error = ""; Aspose.Cells.Workbook wb = new Aspose.Cells.W

C#使用Aspose.Cells导出Excel简单实现

首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出): 1 /// <summary> 2 /// 导出Excel表格 3 /// </summary> 4 /// <param name="list">数据集合</param> 5 /// <param name="heade

excle,aspose.cells 公式字段值取不到 xmls转xml

问题: 一,单元格或列是公式的,读出值为0 aspose.cells 4.4.0.5版本 由于太低,读xmls后缀的excel文件时,发现如果此列是公式算出来的,值是获取不到的.获取到的值一直是0 二,升级可以解决问题.但会有如下问题 1,样式使用改动大 如果升级aspose,此问题可以解决.不过有好多地方要做修改. 2,转pdf打印有问题 如果你对aspose生成好的excle转pdf进行打印.会有断页,行自适应方法后,在excle显示正常,但打印出来后显示不全. 我试了.7.2.1.0版本5

使用Aspose.Cell.dll导出Excel总结

这两天项目上用Aspose导出Excel来着.开始感觉挺简单的,但是实际操作起来还是挺复杂的,调试占的时间很长.主要是动态生成列.合并单元格.调样式占了很长时间,还是总结一下吧. 基础操作: //EXCEL模板路径 var filePath = HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.CurrentPackage.Settings["FilePath"]); //打开模板sheet