前提:
导入COM库:Microsoft word 11.0 Object Library.
引用里面就增加了:
创建新Word
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
打开文档:
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object fileName = @"E:\CCCXCXX\TestDoc.doc";
oDoc = oWord.Documents.Open(ref fileName,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
导入模板
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object fileName = @"E:\XXXCCX\Test.doc";
oDoc = oWord.Documents.Add(ref fileName, ref oMissing,
ref oMissing, ref oMissing);
.添加新表
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
object start = 0;
object end = 0;
Word.Range tableLocation = oDoc.Range(ref start, ref end);
oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);
.表插入行
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
object start = 0;
object end = 0;
Word.Range tableLocation = oDoc.Range(ref start, ref end);
oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);
.单元格合并
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
object start = 0;
object end = 0;
Word.Range tableLocation = oDoc.Range(ref start, ref end);
oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);
Word.Cell cell = newTable.Cell(1, 1);
cell.Merge(newTable.Cell(1, 2));
.单元格分离
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
object start = 0;
object end = 0;
Word.Range tableLocation = oDoc.Range(ref start, ref end);
oDoc.Tables.Add(tableLocation, 3, 4, ref oMissing, ref oMissing);
Word.Table newTable = oDoc.Tables[1];
object beforeRow = newTable.Rows[1];
newTable.Rows.Add(ref beforeRow);
Word.Cell cell = newTable.Cell(1, 1);
cell.Merge(newTable.Cell(1, 2));
object Rownum = 2;
object Columnnum = 2;
cell.Split(ref Rownum, ref Columnnum);
通过段落控制插入
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /**//* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
//Insert a paragraph at the beginning of the document.
Word.Paragraph oPara1;
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Text = "Heading 1";
oPara1.Range.Font.Bold = 1;
oPara1.Format.SpaceAfter = 24; //24 pt spacing after paragraph.
oPara1.Range.InsertParagraphAfter();
我用c#怎么获取word文档中一个table下面的一行字符串,这个字符串在table下面,紧挨着table
先定位table位置,再用选取方法处理,很长时间没有做了代码工作了,table很好定位,可以写个循环,如果下面的代码忘,可以用word中的自定义宏查看相应的与代码再一致到c#中
我要获取的数据不在table表格里,在table表格的外面,我能获取table里面的数据,但是我不知道怎么获取table的位置,word里获取位置不是一般用Paragraphs吗,我不知道怎么获取到这个Paragraphs值
如何在Word文档里面插入漂亮的代码?
如果你会使用调试宏代码,可以到这里去找。
开发工具——VB.
如果在功能区没有见到,就打开word选项/常用/在功能区显示“开发工具”选项卡。
php 怎么实现打印 功能啊 直接打印html中的table 而且为word格式 table里的内容是通过数据库获取出来的
你的打印是不是编程语言里面说的打印,例如basic语言的print语句,如果是的话,在PHP里面使用echo语句打印内容,例如:
echo '<table border=1><tr><td>1<td>2</table>';
如果你是希望程序运行后在打印机上打印输出内容,那可能比较复杂,而且不是PHP的强项,需要编写许多查找打印机的代码,简单的做法是把数据送我特殊设备,可以使用file_put_contents函数,例如:
file_put_contents('PRN:', 'print test');
java 代码生成word文件
没定格式的话可以再jsp页面添加这段:
<%
response.reset();
response.setContentType("application/vnd.ms-excel;charset=utf-8");
java.util.Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
String Starttime = df.format(date).toString();
response.setHeader("Content-disposition", "attachment; filename=GroupingInformation_"+ Starttime + ".doc");
%>
如果要定好格式的话,只有自己去看poi比较复杂。(但是用习惯了就没大问题了。)
poi后台:
导出第三句是格式,这个自己去试试。
我看网上说的poi对于word的支持不太好啊?不是很复杂的word文档,但是里面会有表格和一下描述文字
对了。。。poi后台我导出的Excel。。一般情况下用没定格式的导出word也行,怎么说呢,你加了那段话,系统就直接复制你的页面过去,所以你的页面是什么样子,基本导出就是什么样子的。。。当你跳转这个页面的时候就系统就会问你报存word文件否。。。。word导出,你的table也会出来。
求问如何设置Word表格的VBA代码
Dim i As Table, N As Integer On Error Resume Next ’忽略错误 Application.ScreenUpdating = False ’关闭屏幕更新 For Each i In ActiveDocument.Tables ’在表格中循环 With i .Style = "列表型 4" ’将所有表格设置为"列表型4"的样式 With .Borders ‘边框 .InsideLineStyle = wdLineStyleSingle ’设置内部边框线条 End With With .Rows(1).Borders(wdBorderBottom) ‘第一行的底边框 .LineStyle = wdLineStyleDouble ‘双线型 .LineWidth = wdLineWidth050pt .Color = wdColorAutomatic End With If .Rows.Count > 1 Then ’ 如果表格行数大于1 If Len(.Cell(2, 1).Range) <= 2 Then ’如果第二行第一列不为空 With .Rows(2).Shading ’设置底纹 .Texture = wdTextureNone ’无底底纹 .ForegroundPatternColor = wdColorAutomatic .BackgroundPatternColor = wdColorGray125 End With End If End If For N = 2 To .Columns.Count ’从第二列到最后一列 .Columns(N).Select ’单元格对齐方式为中部居中 Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter Next N End With Next i Application.ScreenUpdating = True 以上的代码功能为:Word表格集合中的循环与对单元格边框的设置。
各位高手大家帮忙看看这张WORD表格的HTML代码怎么写,谢谢了
这个在HTML中用表格实现很简单的。直接新建行和列表格,根据自己的需要,然后填充内容。
<table width="1004" border="1" cellspacing="0" cellpadding="0" style="margin:0 auto;">
<tr>
<td>指标名称</td>
<td>代码</td>
<td>计量单位</td>
<td>本年累计</td>
<td>历年累计</td>
</tr>
<tr>
<td> </td>
<td>01</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
内容自己填。
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="123"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
我其实是看不懂代码的,纯美工,公司逼着我要做HTML的报表,我就是想要一个代码模板,里面的中文我自己填,其实就是这样的,你写的这个代码,我复制进Dreamweaver去后好像和公司给我的Word表格样子不同
公司报表:
你的代码:
如果按照你的说法,公司给你的也不是表格,你见过表格左右没有封闭的吗?最多只可以算多条横线和竖线的架构。
word中怎么一次选中所有表格
1、打开word文档,切换到“视图”选项、标签、点击“宏”选项,然后下拉箭头点击“查看宏”选项或者直接快捷键Alt+F8;
2、在弹出的宏创建对话框,输入宏名字(可以是中文),然后点击右侧“创建”按钮;
3、用所给的代码替换掉默认的内容:Sub SelectAllTables()、Application.ScreenUpdating = False '判断文档是否被保护 If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then MsgBox "文档已保护,此时不能选中多个表格!";
4、粘贴完代码后,直接点击工具栏的运行按钮▶,此时文档中所有表格已经选中,关闭VBA编辑器即可。
转载请注明出处51数据库 » wordtable键代码 c#操作word代码