using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using ET;
namespace WpsAddWord
{
class Program
{
public static string str = "say hello";
static void Main(string[] args)
{
Console.WriteLine(str);
#region
ET.Application execl = new ET.Application();
execl.DisplayAlerts = false;
workbook book = (workbook)execl.Workbooks.Add();
Worksheet sheet = (Worksheet)book.Worksheets.get_Item(1);//代表一张工作薄
ET.Range rg = (ET.Range)sheet.get_Range("A1", "C1");
rg.Value2 = "合拼单元格";
rg.HorizontalAlignment = ETHAlign.etHAlignCenterAcrossSelection;
rg.Merge(true);//合拼单元格
book.SaveAs(@"D:\Users\raolei\Documents\Visual Studio 2010\Projects\WpsAddWord\WpsAddWord\Filed\4新建WPS表格工作簿.xls");
book.Close();
execl.Workbooks.Close();
#endregion
Console.ReadKey();
}
/// <summary>
///
/// </summary>
/// <param name="book">Worksheet对象</param>
/// <param name="value">合拼单元格的值</param>
/// <param name="col">第几列如:A的第一列为ASCII值为65</param>
/// <param name="row">第几行</param>
/// <param name="count">跨列的数</param>
public void Combine(Worksheet book, string value, ref int col, string row, int count)
{
System.Text.ASCIIEncoding coding = new System.Text.ASCIIEncoding();
byte[] x = new byte[] { (byte)col };
string cell = coding.GetString(x) + row;
col += count;
x = new byte[] { (byte)col };
string rows = coding.GetString(x) + row;
Range ran = book.get_Range(cell, rows);
ran.Value2 = value;
ran.HorizontalAlignment = ETHAlign.etHAlignCenterAcrossSelection;//居中
ran.Merge(false);//参数为True则为每一行合并为一个单元格
}
}
}