Silverlight使用Com组件操作Excel的封装类(2)

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;
            }
        }

    }
}
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值