現在基本功能都實作了,就差把word表格居中了,有會的朋友請不吝賜教,謝謝,注意是把表格居中,不是把文字居中。
部分代碼貼在下面,若還需要別的資訊,請聯系!
手機,微信 13522968283,可有償!
void CWordtestDlg::OnNewDoc()
{
COleVariant vTrue((short)TRUE);
COleVariant vFalse((short)FALSE);
COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//////////////////////////////////////////////////////////////////////////
//開始一個新的Microsoft Word實體
_Application oWordApp;
if (!oWordApp.CreateDispatch("Word.Application", NULL))
{
AfxMessageBox("CreateDispatch failed.", MB_OK | MB_SETFOREGROUND);
return;
}
oWordApp.SetVisible(TRUE);
//////////////////////////////////////////////////////////////////////////
//創建一個新的word檔案
Documents oDocs = oWordApp.GetDocuments();
_Document oDoc = oDocs.Add(vOpt, vOpt, vOpt, vOpt);
//把文本添加到word檔案
Selection oSel = oWordApp.GetSelection();
_Font f=oSel.GetFont();
Paragraph format = oSel.GetParagraphFormat();//設定格式
format.SetAlignment(1);//居中
format.SetLineSpacingRule(4);
format.SetLineSpacing(13);
f.SetSize(12);
f.SetBold(1);
oSel.TypeParagraph();
oSel.TypeText("西歐8國15天行程");
oSel.TypeParagraph();
f.SetSize(9);
f.SetBold(0);
oSel.TypeParagraph();
oSel.WholeStory();
// 設定字體——老的
/* _Font font(oSel.GetFont());
//font.SetColor(RGB(255,0,0));
font.SetColor(RGB(0,0,0));
font.SetSize(14.f);
font.SetBold(1);
oSel.SetFont(font);*/
///表格1
oSel.EndKey(COleVariant((short)wdStory), COleVariant((short)wdMove));
Range Rng = oSel.GetRange();
Tables Tbls = oDoc.GetTables();
Table Tb0 = Tbls.Add(Rng, 16, 5, vOpt, vOpt);
Borders bords0 = Tb0.GetBorders();
bords0.SetOutsideLineStyle(wdLineStyleSingle);//設定邊框屬性
bords0.SetOutsideColorIndex(wdBlack);//邊框顏色
bords0.SetOutsideLineWidth(wdLineWidth150pt);//邊框寬度
bords0.SetInsideLineStyle(wdLineStyleSingle);//內框屬性
bords0.SetInsideColorIndex(wdBlack);//內框顏色
f.SetBold(1);
Columns c=oSel.GetColumns();
c.SetWidth(40);
oSel.TypeText(_T("第X天"));
oSel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
f.SetBold(1);
c.SetWidth(50);
oSel.TypeText(_T("日期"));
oSel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
f.SetBold(1);
c.SetWidth(260);
oSel.TypeText(_T("行程安排"));
oSel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
f.SetBold(1);
c.SetWidth(40);
oSel.TypeText(_T("住宿"));
oSel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
f.SetBold(1);
//c.SetWidth(30);
c.SetWidth(100);
oSel.TypeText(_T("用餐"));
oSel.MoveDown(COleVariant((short)4),COleVariant((short)1),COleVariant((short)0));
uj5u.com熱心網友回復:
手機,微信 13522968273,上面的寫錯了,是這個,不好意思!轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/91110.html
標籤:基礎類
下一篇:正則運算式匹配中文逗號分隔開
