asp.net导出Excel类库代码分享(2)

/// <summary>
    /// 插入新行
    /// </summary>
    /// <param>模板行号</param>
    public void insertRow(int y)
    {
        Excel.Range range = sheet.get_Range(GetAix(1, y), GetAix(25, y));
        range.Copy(miss);
        range.Insert(Excel.XlDirection.xlDown, miss);
        range.get_Range(GetAix(1, y), GetAix(25, y));
        range.Select();
        sheet.Paste(miss, miss);


    }

/// <summary>
    /// 把剪切内容粘贴到当前区域
    /// </summary>
    public void past()
    {
        string s = "a,b,c,d,e,f,g";
        sheet.Paste(sheet.get_Range(this.GetAix(10, 10), miss), s);
    }
    /// <summary>
    /// 设置边框
    /// </summary>
    /// <param></param>
    /// <param></param>
    /// <param></param>
    /// <param></param>
    /// <param></param>
    public void setBorder(int x1, int y1, int x2, int y2, int Width)
    {
        Excel.Range range = sheet.get_Range(this.GetAix(x1, y1), miss);


        ((Excel.Range)range.Cells[x1, y1]).ColumnWidth = Width;
    }
    public void mergeCell(int x1, int y1, int x2, int y2)
    {
        Excel.Range range = sheet.get_Range(this.GetAix(x1, y1), this.GetAix(x2, y2));
        range.Merge(true);
    }

public Excel.Range getRange(int x1, int y1, int x2, int y2)
    {
        Excel.Range range = sheet.get_Range(this.GetAix(x1, y1), this.GetAix(x2, y2));
        return range;
    }

private object miss = Missing.Value; //忽略的参数OLENULL
    private Excel.Application m_objExcel;//Excel应用程序实例
    private Excel.Workbooks m_objBooks;//工作表集合
    private Excel.Workbook m_objBook;//当前操作的工作表
    private Excel.Worksheet sheet;//当前操作的表格

public Excel.Worksheet CurrentSheet
    {
        get
        {
            return sheet;
        }
        set
        {
            this.sheet = value;
        }
    }

public Excel.Workbooks CurrentWorkBooks
    {
        get
        {
            return this.m_objBooks;
        }
        set
        {
            this.m_objBooks = value;
        }
    }

public Excel.Workbook CurrentWorkBook
    {
        get
        {
            return this.m_objBook;
        }
        set
        {
            this.m_objBook = value;
        }
    }
    /// <summary>
    /// 打开Excel文件
    /// </summary>
    /// <param>路径</param>
    public void OpenExcelFile(string filename)
    {
        UserControl(false);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgyfy.html