|
|
@@ -1848,6 +1848,200 @@ namespace CallCenter.Utility
|
|
1848
|
1848
|
}
|
|
1849
|
1849
|
|
|
1850
|
1850
|
|
|
|
1851
|
+
|
|
|
1852
|
+
|
|
|
1853
|
+ public string TSDBToExcel( DataTable dt)
|
|
|
1854
|
+ {
|
|
|
1855
|
+ try
|
|
|
1856
|
+ {
|
|
|
1857
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
1858
|
+ ISheet sheet = workbook.CreateSheet("Sheet1");
|
|
|
1859
|
+ ICellStyle cellStyle = workbook.CreateCellStyle();
|
|
|
1860
|
+ NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
|
|
|
1861
|
+ // cellfont.Boldweight = (short)FontBoldWeight.Normal;
|
|
|
1862
|
+ cellStyle.VerticalAlignment = VerticalAlignment.Center;
|
|
|
1863
|
+ cellStyle.Alignment = HorizontalAlignment.Center;
|
|
|
1864
|
+ // cellfont.FontHeightInPoints = 17;
|
|
|
1865
|
+
|
|
|
1866
|
+ cellfont.FontHeight = 300;
|
|
|
1867
|
+ cellStyle.SetFont(cellfont);
|
|
|
1868
|
+ ICellStyle cellStylebt = workbook.CreateCellStyle();
|
|
|
1869
|
+ NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
|
|
|
1870
|
+ cellStylebt.SetFont(cellfontbt);
|
|
|
1871
|
+ cellStylebt.VerticalAlignment = VerticalAlignment.Center;
|
|
|
1872
|
+ cellStylebt.Alignment = HorizontalAlignment.Center;
|
|
|
1873
|
+
|
|
|
1874
|
+
|
|
|
1875
|
+ #region 标题
|
|
|
1876
|
+ ICellStyle cellStylebt1 = workbook.CreateCellStyle();
|
|
|
1877
|
+ NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
|
|
|
1878
|
+ // cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
|
|
|
1879
|
+ cellfontbt1.FontHeight = 500;
|
|
|
1880
|
+ cellStylebt1.SetFont(cellfontbt1);
|
|
|
1881
|
+ cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
|
|
|
1882
|
+ cellStylebt1.Alignment = HorizontalAlignment.Center;
|
|
|
1883
|
+ IRow irow1 = sheet.CreateRow(0);
|
|
|
1884
|
+ ICell cell1 = irow1.CreateCell(0);
|
|
|
1885
|
+ cell1.SetCellValue("各生产单位市场投诉对比情况");
|
|
|
1886
|
+ cell1.CellStyle = cellStylebt1;
|
|
|
1887
|
+ sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 12));
|
|
|
1888
|
+ #endregion
|
|
|
1889
|
+
|
|
|
1890
|
+
|
|
|
1891
|
+ #region
|
|
|
1892
|
+ ICellStyle cellStylebt3 = workbook.CreateCellStyle();
|
|
|
1893
|
+ NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
|
|
|
1894
|
+ // cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
|
|
|
1895
|
+ // cellfontbt3.FontHeight = 400;
|
|
|
1896
|
+ cellfontbt3.FontHeightInPoints = 15;
|
|
|
1897
|
+ cellStylebt3.WrapText = true;//设置换行这个要先设置
|
|
|
1898
|
+ cellStylebt3.SetFont(cellfontbt3);
|
|
|
1899
|
+ cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
|
|
|
1900
|
+ cellStylebt3.Alignment = HorizontalAlignment.Center;
|
|
|
1901
|
+ IRow irow3 = sheet.CreateRow(1);
|
|
|
1902
|
+ IRow irow6 = sheet.CreateRow(2);
|
|
|
1903
|
+
|
|
|
1904
|
+ ICell title1 = irow3.CreateCell(0);
|
|
|
1905
|
+ title1.SetCellValue("生产厂家");
|
|
|
1906
|
+ title1.CellStyle = cellStylebt3;
|
|
|
1907
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 2, 0, 0));
|
|
|
1908
|
+ ICell title12 = irow3.CreateCell(1);
|
|
|
1909
|
+ title12.SetCellValue("总投诉");
|
|
|
1910
|
+ title12.CellStyle = cellStylebt3;
|
|
|
1911
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 1, 3));
|
|
|
1912
|
+
|
|
|
1913
|
+ ICell title13 = irow3.CreateCell(4);
|
|
|
1914
|
+ title13.SetCellValue("杂质异物类(Z**)");
|
|
|
1915
|
+ title13.CellStyle = cellStylebt3;
|
|
|
1916
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 4, 6));
|
|
|
1917
|
+ ICell title14 = irow3.CreateCell(7);
|
|
|
1918
|
+ title14.SetCellValue("破袋发霉类(P)");
|
|
|
1919
|
+ title14.CellStyle = cellStylebt3;
|
|
|
1920
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 7, 9));
|
|
|
1921
|
+ ICell title15 = irow3.CreateCell(10);
|
|
|
1922
|
+ title15.SetCellValue("变质异味类(B)");
|
|
|
1923
|
+ title15.CellStyle = cellStylebt3;
|
|
|
1924
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 10, 12));
|
|
|
1925
|
+
|
|
|
1926
|
+
|
|
|
1927
|
+ ICell title16 = irow6.CreateCell(1);
|
|
|
1928
|
+ title16.SetCellValue("起数");
|
|
|
1929
|
+ title16.CellStyle = cellStylebt3;
|
|
|
1930
|
+
|
|
|
1931
|
+ ICell title17 = irow6.CreateCell(2);
|
|
|
1932
|
+ title17.SetCellValue("同期");
|
|
|
1933
|
+ title17.CellStyle = cellStylebt3;
|
|
|
1934
|
+
|
|
|
1935
|
+ ICell title18 = irow6.CreateCell(3);
|
|
|
1936
|
+ title18.SetCellValue("增幅%");
|
|
|
1937
|
+ title18.CellStyle = cellStylebt3;
|
|
|
1938
|
+
|
|
|
1939
|
+ ICell title19 = irow6.CreateCell(4);
|
|
|
1940
|
+ title19.SetCellValue("起数");
|
|
|
1941
|
+ title19.CellStyle = cellStylebt3;
|
|
|
1942
|
+
|
|
|
1943
|
+ ICell title110 = irow6.CreateCell(5);
|
|
|
1944
|
+ title110.SetCellValue("同期");
|
|
|
1945
|
+ title110.CellStyle = cellStylebt3;
|
|
|
1946
|
+
|
|
|
1947
|
+
|
|
|
1948
|
+ ICell title111 = irow6.CreateCell(6);
|
|
|
1949
|
+ title111.SetCellValue("增幅%");
|
|
|
1950
|
+ title111.CellStyle = cellStylebt3;
|
|
|
1951
|
+
|
|
|
1952
|
+ ICell title112 = irow6.CreateCell(7);
|
|
|
1953
|
+ title112.SetCellValue("起数");
|
|
|
1954
|
+ title112.CellStyle = cellStylebt3;
|
|
|
1955
|
+
|
|
|
1956
|
+ ICell title113 = irow6.CreateCell(8);
|
|
|
1957
|
+ title113.SetCellValue("同期");
|
|
|
1958
|
+ title113.CellStyle = cellStylebt3;
|
|
|
1959
|
+
|
|
|
1960
|
+ ICell title114 = irow6.CreateCell(9);
|
|
|
1961
|
+ title114.SetCellValue("增幅%");
|
|
|
1962
|
+ title114.CellStyle = cellStylebt3;
|
|
|
1963
|
+
|
|
|
1964
|
+
|
|
|
1965
|
+ ICell title1122 = irow6.CreateCell(10);
|
|
|
1966
|
+ title1122.SetCellValue("起数");
|
|
|
1967
|
+ title1122.CellStyle = cellStylebt3;
|
|
|
1968
|
+
|
|
|
1969
|
+ ICell title1133 = irow6.CreateCell(11);
|
|
|
1970
|
+ title1133.SetCellValue("同期");
|
|
|
1971
|
+ title1133.CellStyle = cellStylebt3;
|
|
|
1972
|
+
|
|
|
1973
|
+ ICell title1144 = irow6.CreateCell(12);
|
|
|
1974
|
+ title1144.SetCellValue("增幅%");
|
|
|
1975
|
+ title1144.CellStyle = cellStylebt3;
|
|
|
1976
|
+
|
|
|
1977
|
+
|
|
|
1978
|
+ #endregion
|
|
|
1979
|
+ //建立内容行
|
|
|
1980
|
+ int iRowIndex = 2;
|
|
|
1981
|
+ foreach (DataRow dr in dt.Rows)
|
|
|
1982
|
+ {
|
|
|
1983
|
+ int iCellIndex = 0;
|
|
|
1984
|
+ IRow irow = sheet.CreateRow(iRowIndex + 1);
|
|
|
1985
|
+ for (int i = 0; i < dt.Columns.Count; i++)
|
|
|
1986
|
+ {
|
|
|
1987
|
+ string strsj = string.Empty;
|
|
|
1988
|
+ if (dr[i] != null)
|
|
|
1989
|
+ {
|
|
|
1990
|
+ strsj = dr[i].ToString();
|
|
|
1991
|
+ }
|
|
|
1992
|
+ ICell cell = irow.CreateCell(iCellIndex);
|
|
|
1993
|
+ cell.SetCellValue(strsj);
|
|
|
1994
|
+ cell.CellStyle = cellStyle;
|
|
|
1995
|
+ iCellIndex++;
|
|
|
1996
|
+ }
|
|
|
1997
|
+ iRowIndex++;
|
|
|
1998
|
+ }
|
|
|
1999
|
+
|
|
|
2000
|
+ ////自适应列宽度
|
|
|
2001
|
+ //for (int i = 0; i < 12; i++)
|
|
|
2002
|
+ //{
|
|
|
2003
|
+ // sheet.AutoSizeColumn(i);
|
|
|
2004
|
+ //}
|
|
|
2005
|
+ //自适应列宽度
|
|
|
2006
|
+ for (int i = 0; i < 13; i++)
|
|
|
2007
|
+ {
|
|
|
2008
|
+ //
|
|
|
2009
|
+ sheet.AutoSizeColumn(i);
|
|
|
2010
|
+ // sheet.SetColumnWidth(i, 12 * 400);
|
|
|
2011
|
+ }
|
|
|
2012
|
+
|
|
|
2013
|
+ using (MemoryStream ms = new MemoryStream())
|
|
|
2014
|
+ {
|
|
|
2015
|
+ workbook.Write(ms);
|
|
|
2016
|
+
|
|
|
2017
|
+ HttpContext curContext = HttpContext.Current;
|
|
|
2018
|
+
|
|
|
2019
|
+
|
|
|
2020
|
+ // 设置编码和附件格式
|
|
|
2021
|
+ curContext.Response.ContentType = "application/vnd.ms-excel";
|
|
|
2022
|
+ curContext.Response.ContentEncoding = Encoding.UTF8;
|
|
|
2023
|
+ curContext.Response.Charset = "";
|
|
|
2024
|
+ curContext.Response.AppendHeader("Content-Disposition",
|
|
|
2025
|
+ "attachment;filename=" + HttpUtility.UrlEncode("各生产单位市场投诉对比情况" + ".xls", Encoding.UTF8));
|
|
|
2026
|
+
|
|
|
2027
|
+ curContext.Response.BinaryWrite(ms.GetBuffer());
|
|
|
2028
|
+
|
|
|
2029
|
+ workbook = null;
|
|
|
2030
|
+ ms.Close();
|
|
|
2031
|
+ ms.Dispose();
|
|
|
2032
|
+
|
|
|
2033
|
+ curContext.Response.End();
|
|
|
2034
|
+ }
|
|
|
2035
|
+ return "";
|
|
|
2036
|
+ }
|
|
|
2037
|
+ catch
|
|
|
2038
|
+ {
|
|
|
2039
|
+ return "导出失败!";
|
|
|
2040
|
+ }
|
|
|
2041
|
+ }
|
|
|
2042
|
+
|
|
|
2043
|
+
|
|
|
2044
|
+
|
|
1851
|
2045
|
/// <summary>
|
|
1852
|
2046
|
/// NPOI导出EXCEL
|
|
1853
|
2047
|
/// </summary>
|