LSOOBXlsHelper.cs
using System; using System.IO; using ClientUtils; namespace Longshine.SLLib.LSOOBExcel { public class LSOOBXlsHelper { public static string GetSpecialFolderPath(Environment.SpecialFolder folder) { return Environment.GetFolderPath(folder); } public static string CopyFileToTemp(FileStream fileToCopy, string path, string suffix) { string fileName = path + "\\" + GenerateRandomFileName(suffix); using (FileStream copyToFile = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { fileToCopy.CopyTo(copyToFile); } return fileName; } private static string GenerateRandomFileName(string suffix) { return DateTime.Now.DateTimeConvertToStringNoSpaceAll() + new Random(DateTime.Now.Second).Next(10000).ToString() + "." + suffix; } } }
LSOOBXlsRange.cs
using System.Reflection; namespace Longshine.SLLib.LSOOBExcel { public class LSOOBXlsRange { dynamic range = null; public dynamic Range { get { return range; } set { if (value != null) range = value; } } public object Value { get { return range.Value2; } set { if (value != null) range.Value2 = value; } } /// <summary> /// 合并单元格 /// </summary> public void Merge() { range.Merge(Missing.Value); } /// <summary> /// 列宽为自动适应 /// </summary> public void ColumnsAutoFit() { range.Columns.AutoFit(); // 设置列宽为自动适应 } /// <summary> /// 设置单元格格式为货币格式 /// </summary> public string NumberFormatLocal { get { return range.NumberFormatLocal; } set { if (value != null) range.NumberFormatLocal = value; } } /// <summary> /// 单元格边框 /// </summary> public int LineStyle { get { return range.Borders.LineStyle; } set { range.Borders.LineStyle = value; } } public string FontName { get { return range.Font.Name; } set { if (value != null) range.Borders.LineStyle = value; } } /// <summary> /// 行高 /// </summary> public int RowHeight { get { return range.RowHeight; } set { range.RowHeight = value; } } /// <summary> /// 列宽 /// </summary> public int ColumnWidth { get { return range.ColumnWidth; } set { range.ColumnWidth = value; } } /// <summary> /// 加粗字体 /// </summary> public bool FontBold { get { return range.Font.Bold; } set { range.Font.Bold = value; } } /// <summary> /// 字体大小 /// </summary> public int FontSize { get { return range.Font.Size; } set { range.Font.Size = value; } } /// <summary> /// 字体颜色 /// </summary> public int FontColorIndex { get { return range.Font.ColorIndex; } set { range.Font.ColorIndex = value; } } /// <summary> /// 单元格背景色 /// </summary> public int InteriorColorIndex { get { return range.Interior.ColorIndex; } set { range.Interior.ColorIndex = value; } } /// <summary> /// 文字居中 /// 居中:$FFFFEFF4 /// </summary> public int HorizontalAlignment { get { return range.HorizontalAlignment; } set { range.HorizontalAlignment = value; } } public int VerticalAlignment { get { return range.VerticalAlignment; } set { range.VerticalAlignment = value; } } /// <summary> /// 获得区域的列数 /// </summary> public int ColumnsCount { get { return range.Columns.Count; } } /// <summary> /// 获得区域的行数 /// </summary> public int RowsCount { get { return range.Rows.Count; } } } }
LSOOBXlsRow.cs
namespace Longshine.SLLib.LSOOBExcel { public class LSOOBXlsRow { dynamic row = null; public LSOOBXlsRow() { } public dynamic Row { get { return row; } set { if (value != null) row = value; } } public int FontSize { get { return row.Font.Size; } set { row.Font.Size = value; } } public bool WrapText { get { return row.WrapText; } set { row.WrapText = value; } } public int InteriorColorIndex { get { return row.Interior.ColorIndex; } set { row.Interior.ColorIndex = value; } } public int RowHeight { get { return row.RowHeight; } set { row.RowHeight = value; } } } }
LSOOBXlsColumn.cs
namespace Longshine.SLLib.LSOOBExcel { public class LSOOBXlsColumn { dynamic column = null; public LSOOBXlsColumn() { } public dynamic Column { get { return column; } set { if (value != null) column = value; } } public int ColumnWidth { get { return column.ColumnWidth; } set { column.ColumnWidth = value; } } } }