excel 设置单元格对齐方式

   enum CellHorizonAlignment
	{
		xlCenter = -4108,
		xlLeft   = -4131,
		xlRight  = -4152,
		xlFill   = 5,
		xlJustify= -4130,
		xlCenterAcrossSelection = 7,
		xlDistributed= -4117
	};
	enum CellVerticalAlignment
	{
       xlTop = -4160,
	   xlBottom = -4107,
	   xlvJustify= -4130,
	   xlvDistributed= -4117
	};


//设置单元格对齐方式
void COperExcel::XlsSetCellAlignment(int row, int colum, CellHorizonAlignment horizon, CellVerticalAlignment vertical)
{
	if (!xlsAppIsInit())
	{
		return;
	}
	/*
	row  colum  判断
	*/
	if (!(row >= 1 && colum >= 1))
	{
		;
		return;
	}

	CWorksheet xlsWorkSheet = m_xlsAppLication.get_ActiveSheet();
	if (xlsWorkSheet.m_lpDispatch == NULL)
	{
		return;
	}
	CRange range;
	LPDISPATCH lpDisp = NULL;
	lpDisp = xlsWorkSheet.get_Cells();  //所有表格
	if (lpDisp == NULL)
	{
		return;
	}

	range.AttachDispatch(lpDisp);
	if (range.m_lpDispatch == NULL)
	{
		return;
	}
	
	range.get_Item(_variant_t((long)row), _variant_t((long)colum));
	switch(horizon)
	{
	case COperExcel::xlLeft:
		range.put_HorizontalAlignment(_variant_t(xlLeft));
		break;
	case COperExcel::xlRight:
		range.put_HorizontalAlignment(_variant_t(xlRight));
		break;
	case COperExcel::xlCenter:
		range.put_HorizontalAlignment(_variant_t(xlCenter));
		break;
	case COperExcel::xlFill:
		range.put_HorizontalAlignment(_variant_t(xlFill));
		break;
	case COperExcel::xlJustify:
		range.put_HorizontalAlignment(_variant_t(xlJustify));
		break;
	case COperExcel::xlCenterAcrossSelection:
		range.put_HorizontalAlignment(_variant_t(xlCenterAcrossSelection));
		break;
	case COperExcel::xlDistributed:
		range.put_HorizontalAlignment(_variant_t(xlDistributed));
		break;
	default:
		break;
	}
	switch (vertical)
	{
	case COperExcel::xlTop:
		range.put_VerticalAlignment(_variant_t(xlTop));
		break;
	case COperExcel::xlBottom:
		range.put_VerticalAlignment(_variant_t(xlBottom));
		break;
	case COperExcel::xlJustify:
		range.put_VerticalAlignment(_variant_t(xlJustify));
		break;
	case COperExcel::xlDistributed:
		range.put_VerticalAlignment(_variant_t(xlDistributed));
		break;
	default:
		break;
	}
	range.ReleaseDispatch();
	xlsWorkSheet.ReleaseDispatch();
	lpDisp = NULL;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值