国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

C++程序中導(dǎo)出Word文檔的簡(jiǎn)易方法

2019-11-17 05:20:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

  假如您要在應(yīng)用程序中處理Word文檔,可以參考MSDN. Lori Turner. Automating Microsoft Office 97 and Office 2000,該文內(nèi)容具體全面,但是要在C++程序中導(dǎo)出Word文檔,按照文中的方法來(lái)處理是很麻煩的,非凡是需要填寫的參數(shù)太多,所以我們考慮生成正確的VB腳本,然后執(zhí)行生成Word文檔的操作,這個(gè)方法的優(yōu)點(diǎn)在于:一方面可以少填寫參數(shù);另一方面可以使用在Word中錄制的宏腳本,而只需作少量的修改。我們給出了一些簡(jiǎn)單的函數(shù)來(lái)方便生成Word文檔(主要是簡(jiǎn)單的表格)和直接運(yùn)行內(nèi)存中的VB腳本,此外,還附帶了一個(gè)小小的例子。
//創(chuàng)建Word文檔std::string create_new();//保存Word文檔std::string close_save(const char* filename);//selection 往下移,以繼續(xù)生成下一元素std::string move_down();//插入分段符std::string put_Paragraph();//添加標(biāo)題std::string put_title(const char* title, const char* title_type="標(biāo)題 1", int align=ALIGN_LEFT);//添加“標(biāo)題1”std::string put_title1(const char* title, int align=ALIGN_CENTER);//添加“標(biāo)題2”std::string put_title2(const char* title, int align=ALIGN_LEFT);//添加“標(biāo)題3”std::string put_title3(const char* title, int align=ALIGN_LEFT);//添加紅色警告信息std::string add_warning_msg(const char* msg="無(wú)數(shù)據(jù)");//添加表格的一行數(shù)據(jù)(不用此函數(shù))std::string add_grid_ln(const char* line);//添加表格std::string put_grid(const char* content);//運(yùn)行腳本extern "C" void RunScript(const char* script_str);   下面是一個(gè)小例子,我們期望它在您的計(jì)算機(jī)上能夠很好的運(yùn)行,程序?qū)⑸梢粋€(gè)Word文檔,路徑位于c:/test.doc,計(jì)算機(jī)上需要安裝Word XP。 int main(int argc, char* argv[]){ ostringstream ostr; ostr<<create_new(); ostr<<put_title1("統(tǒng)計(jì)結(jié)果"); ostr<<put_title2("統(tǒng)計(jì)子項(xiàng)具體信息"); std::string str_buffer; read_file_as_grid_content("tab.txt", str_buffer); ostr<<put_Paragraph(); ostr<<put_grid(str_buffer.c_str()); ostr<<close_save("c://test.doc"); //輸出到文件看看VB腳本的內(nèi)容 /* std::ofstream ofile; ofile.open("c://temp.vbs"); ofile<<ostr.str().c_str(); ofile.close(); */ //BeginWaitCursor(); RunScript( ostr.str().c_str() );//運(yùn)行生成的腳本 //EndWaitCursor(); return 0;}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 敦化市| 丽江市| 铜鼓县| 北辰区| 油尖旺区| 襄垣县| 玉环县| 富平县| 宝山区| 龙州县| 高雄县| 朝阳区| 宝坻区| 宁南县| 镇远县| 遂昌县| 青河县| 沙田区| 海南省| 墨江| 方城县| 德格县| 钟山县| 安丘市| 新河县| 聊城市| 阿合奇县| 清镇市| 玉屏| 建德市| 京山县| 汉源县| 青铜峡市| 开鲁县| 长海县| 大化| 云南省| 宝应县| 略阳县| 舟山市| 收藏|