代码如下:
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 name="objExcel">Excel.Application</param>
public ExcelClass(Excel.Application objExcel)
{
this.m_objExcel = objExcel;
}
/// <summary>
/// 列标号
/// </summary>
private string AList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/// <summary>
/// 获取描述区域的字符
/// </summary>
/// <param name="x"></param>
/// <param name="y"></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 name="x">行号</param>
/// <param name="y">列号</param>
/// <param name="align">对齐(CENTER、LEFT、RIGHT)</param>
/// <param name="text">值</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;
}
新闻热点
疑难解答
图片精选