110,556
社区成员
发帖
与我相关
我的任务
分享
string savepath = "";
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
savepath = folderBrowserDialog1.SelectedPath;
}
Object Nothing = System.Reflection.Missing.Value;
object filename = savepath + "/" + "日报";
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
WordDoc.Paragraphs.First.Range.Text = "制表人:" + list[0].Recorder+" " + list[0].RecordTime;
WordDoc.Paragraphs.First.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
Microsoft.Office.Interop.Word.Table table = WordDoc.Tables.Add(WordApp.Selection.Range,list.Count+1 , 14, ref Nothing, ref Nothing);
table.Cell(1, 1).Range.Text = "序号";
table.Cell(1, 2).Range.Text = "航段";
table.Cell(1, 3).Range.Text = "海山";
table.Cell(1, 4).Range.Text = "站号";
table.Cell(1, 5).Range.Text = "采样方式";
table.Cell(1, 6).Range.Text = "经度";
table.Cell(1, 7).Range.Text = "纬度";
table.Cell(1, 8).Range.Text = "水深";
table.Cell(1, 9).Range.Text = "样品号";
table.Cell(1, 10).Range.Text = "岩心长度";
table.Cell(1, 11).Range.Text = "壳层厚度";
table.Cell(1, 12).Range.Text = "基岩厚度";
table.Cell(1, 13).Range.Text = "样品箱号";
table.Cell(1, 14).Range.Text = "备注";
for (int i = 0; i < list.Count; i++)
{
Ocean_ListOfDrill_Sediment temp = list[i];
table.Cell(i + 2, 1).Range.Text = (i+1).ToString();
table.Cell(i + 2, 2).Range.Text = temp.StationNum.LegInfo.Name;
table.Cell(i + 2, 3).Range.Text = temp.StationNum.SeaArea.PositionName;
table.Cell(i + 2, 4).Range.Text = temp.StationNum.SiteCode;
table.Cell(i + 2, 5).Range.Text = temp.StationNum.SamplingStyle.SamplingStyle;
table.Cell(i + 2, 6).Range.Text = temp.StationNum.Longitude.ToString();
table.Cell(i + 2, 7).Range.Text = temp.StationNum.Latitude.ToString();
table.Cell(i + 2, 8).Range.Text = temp.StationNum.WaterDepth;
table.Cell(i + 2, 9).Range.Text = temp.SampleNum;
table.Cell(i + 2, 10).Range.Text = temp.RockLength;
table.Cell(i + 2, 11).Range.Text = temp.ShellThickness;
table.Cell(i + 2, 12).Range.Text = temp.RockThickness;
table.Cell(i + 2, 13).Range.Text = temp.BoxNum;
table.Cell(i + 2, 14).Range.Text = temp.Remark;
}
list.Clear();
WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
MessageBox.Show("导出成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
WordDoc.Paragraphs.First.Range.Text = "制表人:" + list[0].Recorder.Name+" " + list[0].RecordTime;
WordDoc.Paragraphs.First.Range.Text = "头部分:";
object unit = 1;
object count = 1;
unit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
WordApp.Selection.EndKey(ref unit, ref Nothing);
WordDoc.Application.Selection.TypeText("测试测试测试 ");
Sub Macro5()
'
' Macro5 Macro
' 宏在 2010-10-19 由 雨林木风 录制
'
With Selection.Font
.NameFarEast = "黑体"
.NameAscii = "Times New Roman"
.NameOther = "Times New Roman"
.Name = "Times New Roman"
.Size = 10.5
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 1
.Animation = wdAnimationNone
.DisableCharacterSpaceGrid = False
.EmphasisMark = wdEmphasisMarkNone
End With
End Sub