Пример #1
0
        public static MemoryStream Export(DataTable data, string fileName)
        {
            HSSFWorkbook book  = new HSSFWorkbook();
            ISheet       sheet = book.CreateSheet(fileName);

            CreaHeader(data, sheet);

            if (data != null)
            {
                for (int i = 0; i < data.Rows.Count; i++)
                {
                    IRow    row     = sheet.CreateRow(sheet.LastRowNum + 1);
                    DataRow dataRow = data.Rows[i];

                    for (int j = 0; j < data.Columns.Count; j++)
                    {
                        ICell cell = row.CreateCell(j);
                        cell.SetCellValue(ConvertHelper.ToString(dataRow[j]));
                    }
                }
            }

            MemoryStream ms = new MemoryStream();

            book.Write(ms);
            ms.Seek(0, SeekOrigin.Begin);

            return(ms);
        }
Пример #2
0
        /// <summary>
        /// 生成验证码
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GenerateCode(int length = 4)
        {
            Random rd   = new Random();
            string code = string.Empty;

            for (int i = 0; i < length; i++)
            {
                code += ConvertHelper.ToString(rd.Next(0, 9));
            }

            return(code);
        }