using System;
using System.Collections.Generic;
using System.Reflection;
using System.Web;
using Excel = Microsoft.Office.Interop.Excel;
/// <summary>
///ExcelClass 的摘要说明
/// </summary>
public class ExcelClass
{
/// <summary>
/// 构建ExcelClass类
/// </summary>
public ExcelClass()
{
this.m_objExcel = new Excel.Application();
}
/// <summary>
/// 构建ExcelClass类
/// </summary>
/// <param>Excel.Application</param>
public ExcelClass(Excel.Application objExcel)
{
this.m_objExcel = objExcel;
}
/// <summary>
/// 列标号
/// </summary>
private string AList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/// <summary>
/// 获取描述区域的字符
/// </summary>
/// <param></param>
/// <param></param>
/// <returns></returns>
public string GetAix(int x, int y)
{
char[] AChars = AList.ToCharArray();
if (x >= 26) { return ""; }
string s = "";
s = s + AChars[x - 1].ToString();
s = s + y.ToString();
return s;
}
/// <summary>
/// 给单元格赋值1
/// </summary>
/// <param>行号</param>
/// <param>列号</param>
/// <param>对齐(CENTER、LEFT、RIGHT)</param>
/// <param>值</param>
public void setValue(int y, int x, string align, string text)
{
Excel.Range range = sheet.get_Range(this.GetAix(x, y), miss);
range.set_Value(miss, text);
if (align.ToUpper() == "CENTER")
{
range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
}
if (align.ToUpper() == "LEFT")
{
range.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
}
if (align.ToUpper() == "RIGHT")
{
range.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
}
}
/// <summary>
/// 给单元格赋值2
/// </summary>
/// <param>行号</param>
/// <param>列号</param>
/// <param>值</param>
public void setValue(int y, int x, string text)
{
Excel.Range range = sheet.get_Range(this.GetAix(x, y), miss);
range.set_Value(miss, text);
}
/// <summary>
/// 给单元格赋值3
/// </summary>
/// <param>行号</param>
/// <param>列号</param>
/// <param>值</param>
/// <param>字符格式</param>
/// <param>颜色</param>
public void setValue(int y, int x, string text, System.Drawing.Font font, System.Drawing.Color color)
{
this.setValue(x, y, text);
Excel.Range range = sheet.get_Range(this.GetAix(x, y), miss);
range.Font.Size = font.Size;
range.Font.Bold = font.Bold;
range.Font.Color = color;
range.Font.Name = font.Name;
range.Font.Italic = font.Italic;
range.Font.Underline = font.Underline;
}