本文整理汇总了C#中Microsoft.Office.Interop.Word.Application.CentimetersToPoints方法的典型用法代码示例。如果您正苦于以下问题:C# Application.CentimetersToPoints方法的具体用法?C# Application.CentimetersToPoints怎么用?C# Application.CentimetersToPoints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Word.Application
的用法示例。
在下文中一共展示了Application.CentimetersToPoints方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveAsWordDocument
private void SaveAsWordDocument()
{
DateTime beginSessionDate, endSessionDate;
DetectSessionDates(out beginSessionDate, out endSessionDate);
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
Word._Application oWord = new Word.Application();
oWord.Visible = true;
Word._Document oDoc =
oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
var faculties = _sRepo.GetAllFaculties();
for (int facCounter = 0; facCounter < Constants.Constants.facultyGroups.Keys.Count; facCounter++)
{
var groupIds = new List<int>();
foreach (var group in Constants.Constants.facultyGroups.ElementAt(facCounter).Value)
{
var groupId = _sRepo.FindStudentGroup(group);
if (groupId != null)
{
groupIds.Add(groupId.StudentGroupId);
}
}
var facultyExams = _repo.GetFacultyExams(_sRepo, groupIds);
facultyExams = facultyExams.OrderBy(fe => fe.Key).ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value);
Word.Paragraph oPara1 =
oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Font.Size = 24;
oPara1.Format.LineSpacing = oWord.LinesToPoints(1);
oPara1.Range.Text = "Расписание";
oPara1.Format.SpaceAfter = 0;
oPara1.Range.InsertParagraphAfter();
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Font.Size = 14;
oPara1.Format.SpaceAfter = 0;
if (beginSessionDate.Month < 3)
{
var startYear = beginSessionDate.Year - 1;
oPara1.Range.Text = "зимней сессии " + startYear + "-" + (startYear + 1) + " учебного года" +
Environment.NewLine + Constants.Constants.facultyTitles[facCounter];
}
else
{
var startYear = beginSessionDate.Year - 1;
oPara1.Range.Text = "летней сессии " + startYear + "-" + (startYear + 1) + " учебного года" +
Environment.NewLine + Constants.Constants.facultyTitles[facCounter];
}
oPara1.Range.InsertParagraphAfter();
Word.Shape signBox = oDoc.Shapes
.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 350, 15, 200, 75, oPara1.Range);
signBox.Line.Visible = MsoTriState.msoFalse;
signBox.TextFrame.ContainingRange.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphRight;
signBox.TextFrame.ContainingRange.InsertAfter("«УТВЕРЖДАЮ»");
signBox.TextFrame.ContainingRange.InsertParagraphAfter();
signBox.TextFrame.ContainingRange.InsertAfter("Проректор по учебной работе");
signBox.TextFrame.ContainingRange.InsertParagraphAfter();
signBox.TextFrame.ContainingRange.InsertAfter("____________ А.В. Синицкий");
var groups = Constants.Constants.facultyGroups.ElementAt(facCounter).Value;
Word.Table oTable;
Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oTable = oDoc.Tables.Add(wrdRng, 1 + facultyExams.Keys.Count, 1 + groups.Count);
//oTable.Rows(1).HeadingFormat = True;
//oTable.ApplyStyleHeadingRows = True;
oTable.Rows[1].HeadingFormat = -1;
oTable.ApplyStyleHeadingRows = true;
oTable.Borders.Enable = 1;
for (int i = 1; i <= oTable.Rows.Count; i++)
{
oTable.Rows[i].AllowBreakAcrossPages = (int)Microsoft.Office.Core.MsoTriState.msoFalse;
}
oTable.Cell(1, 1).Range.Text = "Дата";
oTable.Cell(1, 1).Range.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter;
for (var column = 1; column <= groups.Count; column++)
{
//.........这里部分代码省略.........
示例2: ExportGroupSchedulePage
public static void ExportGroupSchedulePage(ScheduleRepository repo, MainEditForm form, int groupId,
bool weekFilteredF, int weekFilterNum,
bool onlyFutureDates, CancellationToken cToken)
{
cToken.ThrowIfCancellationRequested();
//Start Word and create a new document.
_Application oWord = new Application { Visible = true };
_Document oDoc = oWord.Documents.Add();
oDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
var group = repo.StudentGroups.GetStudentGroup(groupId);
var sStarts = repo.CommonFunctions.GetSemesterStarts();
cToken.ThrowIfCancellationRequested();
var weekFilter = -1;
if (weekFilteredF)
{
weekFilter = weekFilterNum;
}
var groupLessons = repo.Lessons.GetGroupedGroupLessons(group.StudentGroupId, sStarts, weekFilter, false, onlyFutureDates);
cToken.ThrowIfCancellationRequested();
List<GroupTableView> groupEvents = form.CreateGroupTableView(group.StudentGroupId, groupLessons, false);
Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Table oTable = oDoc.Tables.Add(wrdRng, 1 + groupEvents.Count, 7);
oTable.Borders.Enable = 1;
oTable.Range.ParagraphFormat.SpaceAfter = 0.0F;
oTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oTable.Range.Font.Size = 10;
oTable.Range.Font.Bold = 0;
oTable.Cell(1, 1).Range.Text = group.Name;
oTable.Cell(1, 1).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Columns[1].Width = oWord.CentimetersToPoints(2.44f);
const float colWidth = 25.64F / 6;
for (int j = 1; j <= 6; j++)
{
oTable.Columns[j + 1].Width = oWord.CentimetersToPoints(colWidth);
oTable.Cell(1, j + 1).Range.Text = Constants.DowLocal[j];
oTable.Cell(1, j + 1).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
}
for (int j = 0; j < groupEvents.Count; j++)
{
cToken.ThrowIfCancellationRequested();
oTable.Cell(j + 2, 1).Range.Text = groupEvents[j].Time;
oTable.Cell(j + 2, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 1).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Cell(j + 2, 2).Range.Text = groupEvents[j].MonEvents;
oTable.Cell(j + 2, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 3).Range.Text = groupEvents[j].TueEvents;
oTable.Cell(j + 2, 3).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 4).Range.Text = groupEvents[j].WenEvents;
oTable.Cell(j + 2, 4).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 5).Range.Text = groupEvents[j].ThuEvents;
oTable.Cell(j + 2, 5).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 6).Range.Text = groupEvents[j].FriEvents;
oTable.Cell(j + 2, 6).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 7).Range.Text = groupEvents[j].SatEvents;
oTable.Cell(j + 2, 7).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
}
cToken.ThrowIfCancellationRequested();
int pageCount;
float fontSize = 10.5F;
do
{
fontSize -= 0.5F;
oTable.Range.Font.Size = fontSize;
if (fontSize <= 3)
{
break;
}
pageCount = oDoc.ComputeStatistics(WdStatistic.wdStatisticPages);
} while (pageCount > 1);
}
示例3: ExportSchedulePage
public static void ExportSchedulePage(ScheduleRepository repo, string filename, bool save, bool quit,
int lessonLength, int facultyId, int dayOfWeek, int daysOfWeek, bool weekFiltered, int weekFilter,
bool weeksMarksVisible, bool onlyFutureDates, CancellationToken cToken)
{
object oMissing = Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
cToken.ThrowIfCancellationRequested();
//Start Word and create a new document.
_Application oWord = new Application { Visible = true };
_Document oDoc = oWord.Documents.Add();
oDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
var faculty = repo.Faculties.GetFaculty(facultyId);
var dow = Constants.DowLocal[dayOfWeek];
var schedule = repo.Lessons.GetFacultyDowSchedule(faculty.FacultyId, dayOfWeek, weekFiltered, weekFilter, false, onlyFutureDates);
Paragraph oPara1 = oDoc.Content.Paragraphs.Add();
oPara1.Range.Text = "Расписание";
oPara1.Range.Font.Bold = 0;
oPara1.Range.Font.Size = 10;
oPara1.Range.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
oPara1.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
oPara1.SpaceAfter = 0;
oPara1.Range.InsertParagraphAfter();
var textBoxRange = oPara1.Range;
oPara1 = oDoc.Content.Paragraphs.Add();
//oPara1.Range.Text = "второго семестра 2013 – 2014 учебного года";
oPara1.Range.Text = DetectSemesterString(repo);
oPara1.Range.Font.Bold = 0;
oPara1.Range.Font.Size = 10;
oPara1.Range.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
oPara1.Range.InsertParagraphAfter();
oPara1 = oDoc.Content.Paragraphs.Add();
oPara1.Range.Text = faculty.Name;
oPara1.Range.Font.Bold = 0;
oPara1.Range.Font.Size = 10;
oPara1.Range.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
oPara1.Range.InsertParagraphAfter();
oPara1 = oDoc.Content.Paragraphs.Add();
oPara1.Range.Font.Size = 14;
oPara1.Range.Text = dow.ToUpper();
oPara1.Range.Font.Bold = 1;
oPara1.Range.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
oPara1.Range.InsertParagraphAfter();
Shape cornerStamp = oDoc.Shapes.AddTextbox(
MsoTextOrientation.msoTextOrientationHorizontal,
oWord.CentimetersToPoints(22f),
oWord.CentimetersToPoints(0.5f),
200, 50,
textBoxRange);
cornerStamp.TextFrame.TextRange.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
if (dow == "Понедельник")
{
var prorUchRabNameOption = repo.ConfigOptions.GetFirstFiltredConfigOption(co => co.Key == "Проректор по учебной работе");
var prorUchRabName = (prorUchRabNameOption == null) ? "" : prorUchRabNameOption.Value;
cornerStamp.TextFrame.TextRange.Text = @"«УТВЕРЖДАЮ»" +
Environment.NewLine + "Проректор по учебной работе" +
Environment.NewLine + "______________ " + prorUchRabName;
cornerStamp.TextFrame.TextRange.Font.Size = 10;
cornerStamp.TextFrame.TextRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
}
cornerStamp.TextFrame.WordWrap = 1;
cornerStamp.TextFrame.TextRange.ParagraphFormat.SpaceAfter = 0;
cornerStamp.Line.Visible = MsoTriState.msoFalse;
var timeList = new List<string>();
foreach (var group in schedule)
{
foreach (var time in group.Value.Keys)
{
if (!timeList.Contains(time))
{
timeList.Add(time);
}
}
}
Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
cToken.ThrowIfCancellationRequested();
//.........这里部分代码省略.........
示例4: ExportTwoDaysInPageFacultySchedule
internal static void ExportTwoDaysInPageFacultySchedule(
ScheduleRepository repo, string filename, bool save, bool quit,
int lessonLength, int facultyId, int daysOfWeek,
bool weekFiltered, int weekFilter, bool weeksMarksVisible)
{
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
_Application oWord = new Application { Visible = true };
_Document oDoc = oWord.Documents.Add();
oDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
int currentPageNum = 1;
var faculty = repo.Faculties.GetFaculty(facultyId);
for (int dayOfWeek = 1; dayOfWeek <= 5; dayOfWeek += 2)
{
var firstDaySchedule = repo.Lessons.GetFacultyDowSchedule(faculty.FacultyId, dayOfWeek, weekFiltered, weekFilter, false, false);
var firstDayTable = PutDayScheduleInWord(repo, lessonLength, weeksMarksVisible, firstDaySchedule, oDoc, oEndOfDoc, oWord, null, dayOfWeek);
var secondDaySchedule = repo.Lessons.GetFacultyDowSchedule(faculty.FacultyId, dayOfWeek + 1, weekFiltered, weekFilter, false, false);
var secondDayTable = PutDayScheduleInWord(repo, lessonLength, weeksMarksVisible, secondDaySchedule, oDoc, oEndOfDoc, oWord, firstDayTable, dayOfWeek + 1);
var fontSize = 10.5F;
int pageCount;
do
{
fontSize -= 0.5F;
firstDayTable.Range.Font.Size = fontSize;
if (secondDayTable != null)
{
secondDayTable.Range.Font.Size = fontSize;
}
if (fontSize <= 3)
{
break;
}
pageCount = oDoc.ComputeStatistics(WdStatistic.wdStatisticPages);
} while (pageCount > currentPageNum);
var endOfDoc = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
endOfDoc.Font.Size = 1;
endOfDoc.InsertBreak(WdBreakType.wdSectionBreakNextPage);
currentPageNum++;
}
oDoc.Undo();
if (save)
{
object fileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + filename;
oDoc.SaveAs(ref fileName);
}
if (quit)
{
oWord.Quit();
}
Marshal.ReleaseComObject(oWord);
}
示例5: AuditoriumsExport
public static void AuditoriumsExport(ScheduleRepository repo,
Dictionary<int, Dictionary<int, List<string>>> auds,
int dow, bool addTeacherFio, CancellationToken cToken)
{
cToken.ThrowIfCancellationRequested();
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
_Application oWord = new Application { Visible = true };
_Document oDoc = oWord.Documents.Add();
oDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
/*
Paragraph oPara1 = oDoc.Content.Paragraphs.Add();
oPara1.Range.Text = Constants.DowLocal[dow];
oPara1.Range.Font.Bold = 0;
oPara1.Range.Font.Size = 10;
oPara1.Range.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
oPara1.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
oPara1.SpaceAfter = 0;
oPara1.Range.InsertParagraphAfter();
*/
Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
var audIdsList = new List<int>();
foreach (var r in auds)
{
foreach (var a in r.Value)
{
if (!audIdsList.Contains(a.Key))
{
audIdsList.Add(a.Key);
}
}
}
var rings = repo.Rings.GetAllRings();
var audsById = repo.Auditoriums.GetAll().ToDictionary(a => a.AuditoriumId, a => a.Name);
audIdsList = audIdsList.OrderBy(id => audsById[id]).ToList();
cToken.ThrowIfCancellationRequested();
Table oTable = oDoc.Tables.Add(wrdRng, 1 + auds.Count, 1 + audIdsList.Count);
oTable.Borders.Enable = 1;
oTable.Range.ParagraphFormat.SpaceAfter = 0.0F;
oTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oTable.Range.Font.Size = 10;
oTable.Range.Font.Bold = 0;
oTable.Cell(1, 1).Range.Text = Constants.DowLocal[dow];
oTable.Cell(1, 1).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Columns[1].Width = oWord.CentimetersToPoints(2.44f);
float colWidth = 25.64F / audIdsList.Count;
for (int i = 0; i < audIdsList.Count; i++)
{
oTable.Columns[i + 2].Width = oWord.CentimetersToPoints(colWidth);
oTable.Cell(1, i + 2).Range.Text = audsById[audIdsList[i]];
oTable.Cell(1, i + 2).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Cell(1, i + 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
}
for (int i = 0; i < auds.Count; i++)
{
cToken.ThrowIfCancellationRequested();
var ct = rings.First(r => r.RingId == auds.Keys.ElementAt(i)).Time.ToString("H:mm");
oTable.Cell(2 + i, 1).Range.Text = ct;
oTable.Cell(2 + i, 1).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Cell(2 + i, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
for (int j = 0; j < audIdsList.Count; j++)
{
var audText = "";
if (auds[auds.Keys.ElementAt(i)].ContainsKey(audIdsList[j]))
{
var cnt = auds[auds.Keys.ElementAt(i)][audIdsList[j]].Count;
int ii = 0;
foreach (var kvp in auds[auds.Keys.ElementAt(i)][audIdsList[j]])
{
if (kvp.Contains('@'))
{
audText += kvp.Split('@')[0];
if (addTeacherFio)
{
audText += " " + kvp.Substring(kvp.Split('@')[0].Length + 1);
}
//.........这里部分代码省略.........
示例6: WordSchoolTwoDays
public static void WordSchoolTwoDays(ScheduleRepository repo, string filename, bool save, bool quit, int lessonLength, int facultyId, int dayOfWeek, int daysOfWeek, bool weekFiltered, int weekFilter, bool weeksMarksVisible, CancellationToken cToken)
{
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
_Application oWord = new Application { Visible = true };
_Document oDoc = oWord.Documents.Add();
oDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
var faculty = repo.Faculties.GetFaculty(facultyId);
var oTable = GetAndPutDowSchedule(repo, lessonLength, dayOfWeek, weekFiltered, weekFilter, weeksMarksVisible, faculty, oDoc, oEndOfDoc, oWord, null, cToken);
if (dayOfWeek != 7)
{
oTable = GetAndPutDowSchedule(repo, lessonLength, dayOfWeek + 1, weekFiltered, weekFilter, weeksMarksVisible, faculty, oDoc, oEndOfDoc, oWord, oTable, cToken);
}
int pageCount;
var fontSize = 10.5F;
do
{
fontSize -= 0.5F;
oTable.Range.Font.Size = fontSize;
if (fontSize <= 3)
{
break;
}
pageCount = oDoc.ComputeStatistics(WdStatistic.wdStatisticPages);
} while (pageCount > 1);
if (save)
{
object fileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + filename;
oDoc.SaveAs(ref fileName);
}
if (quit)
{
oWord.Quit();
}
Marshal.ReleaseComObject(oWord);
}
示例7: WordStartSchool
public static void WordStartSchool(ScheduleRepository repo, string filename, bool save, bool quit, int lessonLength, int facultyId, int dayOfWeek, int daysOfWeek, bool weekFiltered, int weekFilter, bool weeksMarksVisible, CancellationToken cToken)
{
cToken.ThrowIfCancellationRequested();
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
_Application oWord = new Application { Visible = true };
_Document oDoc = oWord.Documents.Add();
oDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
var faculty = repo.Faculties.GetFaculty(facultyId);
Paragraph oPara1 = oDoc.Content.Paragraphs.Add();
oPara1.Range.Text = "Расписание " + DetectSemesterString(repo);
oPara1.Range.Font.Bold = 0;
oPara1.Range.Font.Size = 10;
oPara1.Range.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
oPara1.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
oPara1.SpaceAfter = 0;
oPara1.Range.InsertParagraphAfter();
var textBoxRange = oPara1.Range;
oPara1 = oDoc.Content.Paragraphs.Add();
oPara1.Range.Font.Size = 14;
oPara1.Range.Text = Constants.DowLocal[dayOfWeek].ToUpper();
oPara1.Range.Font.Bold = 1;
oPara1.Range.Font.Underline = WdUnderline.wdUnderlineSingle;
oPara1.Range.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
oPara1.Range.InsertParagraphAfter();
Shape cornerStamp = oDoc.Shapes.AddTextbox(
MsoTextOrientation.msoTextOrientationHorizontal,
oWord.CentimetersToPoints(22f),
oWord.CentimetersToPoints(0.5f),
200, 50,
textBoxRange);
cornerStamp.TextFrame.TextRange.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
if (dayOfWeek == 1)
{
cornerStamp.TextFrame.TextRange.Text = @"«УТВЕРЖДАЮ»" +
Environment.NewLine +
"Ректор ______________ Наянова М.В. «___» ____________ 20__ г.";
cornerStamp.TextFrame.TextRange.Font.Size = 10;
cornerStamp.TextFrame.TextRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
}
cornerStamp.TextFrame.WordWrap = 1;
cornerStamp.TextFrame.TextRange.ParagraphFormat.SpaceAfter = 0;
cornerStamp.Line.Visible = MsoTriState.msoFalse;
cToken.ThrowIfCancellationRequested();
Table oTable = GetAndPutDowStartSchedule(repo, lessonLength, dayOfWeek, weekFiltered, weekFilter, weeksMarksVisible, faculty, oDoc, oEndOfDoc, oWord, cToken);
Table oTable2 = null;
if ((dayOfWeek != 6) && (dayOfWeek != 7))
{
oPara1 = oDoc.Content.Paragraphs.Add();
oPara1.Range.Font.Size = 14;
oPara1.Range.Text = Constants.DowLocal[dayOfWeek + 1].ToUpper();
oPara1.Range.Font.Bold = 1;
oPara1.Range.Font.Underline = WdUnderline.wdUnderlineSingle;
oPara1.Range.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
oPara1.Range.InsertParagraphAfter();
oTable2 = GetAndPutDowStartSchedule(repo, lessonLength, dayOfWeek + 1, weekFiltered, weekFilter, weeksMarksVisible, faculty, oDoc, oEndOfDoc, oWord, cToken);
}
cToken.ThrowIfCancellationRequested();
int pageCount;
var fontSize = 10.5F;
do
{
fontSize -= 0.5F;
oTable.Range.Font.Size = fontSize;
if (oTable2 != null)
{
oTable2.Range.Font.Size = fontSize;
}
if (fontSize <= 3)
{
break;
}
pageCount = oDoc.ComputeStatistics(WdStatistic.wdStatisticPages);
} while (pageCount > 1);
//.........这里部分代码省略.........
示例8: ExportWholeScheduleOneGroupPerPage
public static void ExportWholeScheduleOneGroupPerPage(ScheduleRepository repo, MainEditForm form, CancellationToken cToken)
{
cToken.ThrowIfCancellationRequested();
//Start Word and create a new document.
_Application oWord = new Application { Visible = true };
_Document oDoc = oWord.Documents.Add();
oDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
int pageCounter = 0;
foreach (var faculty in repo.Faculties.GetAllFaculties())
{
//var faculty = repo.GetFirstFiltredFaculty(f => f.SortingOrder == i);
var facultyGroups = repo.Faculties.GetFacultyGroups(faculty.FacultyId);
foreach (var group in facultyGroups)
{
cToken.ThrowIfCancellationRequested();
var sStarts = repo.CommonFunctions.GetSemesterStarts();
var groupLessons = repo.Lessons.GetGroupedGroupLessons(group.StudentGroupId, sStarts, -1, false, false);
var groupEvents = form.CreateGroupTableView(group.StudentGroupId, groupLessons, false);
Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Table oTable = oDoc.Tables.Add(wrdRng, 1 + groupEvents.Count, 7);
oTable.Borders.Enable = 1;
oTable.Range.ParagraphFormat.SpaceAfter = 0.0F;
oTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oTable.Range.Font.Size = 10;
oTable.Range.Font.Bold = 0;
oTable.Cell(1, 1).Range.Text = group.Name;
oTable.Cell(1, 1).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Columns[1].Width = oWord.CentimetersToPoints(2.44f);
const float colWidth = 25.64F / 6;
for (int j = 1; j <= 6; j++)
{
oTable.Columns[j + 1].Width = oWord.CentimetersToPoints(colWidth);
oTable.Cell(1, j + 1).Range.Text = Constants.DowLocal[j];
oTable.Cell(1, j + 1).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
}
for (int j = 0; j < groupEvents.Count; j++)
{
cToken.ThrowIfCancellationRequested();
oTable.Cell(j + 2, 1).Range.Text = groupEvents[j].Time;
oTable.Cell(j + 2, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 1).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Cell(j + 2, 2).Range.Text = groupEvents[j].MonEvents;
oTable.Cell(j + 2, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 3).Range.Text = groupEvents[j].TueEvents;
oTable.Cell(j + 2, 3).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 4).Range.Text = groupEvents[j].WenEvents;
oTable.Cell(j + 2, 4).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 5).Range.Text = groupEvents[j].ThuEvents;
oTable.Cell(j + 2, 5).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 6).Range.Text = groupEvents[j].FriEvents;
oTable.Cell(j + 2, 6).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
oTable.Cell(j + 2, 7).Range.Text = groupEvents[j].SatEvents;
oTable.Cell(j + 2, 7).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
}
pageCounter++;
int pageCount;
float fontSize = 10.5F;
do
{
fontSize -= 0.5F;
oTable.Range.Font.Size = fontSize;
if (fontSize <= 3)
{
break;
}
pageCount = oDoc.ComputeStatistics(WdStatistic.wdStatisticPages);
} while (pageCount > pageCounter);
var endOfDoc = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
endOfDoc.Font.Size = 1;
endOfDoc.InsertBreak(WdBreakType.wdSectionBreakNextPage);
}
//.........这里部分代码省略.........
示例9: TeachersSchedule
public static void TeachersSchedule(ScheduleRepository repo, TeacherSchedule tsForm, bool OnlyFutureDates, CancellationToken cToken)
{
var teachers = repo.Teachers.GetAllTeachers().OrderBy(t => t.FIO).ToList();
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
int pageCounter = 0;
//Start Word and create a new document.
_Application oWord = new Application { Visible = true };
_Document oDoc = oWord.Documents.Add();
oDoc.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
foreach (var teacher in teachers)
{
var result = tsForm.GetTeacherScheduleToView(teacher.TeacherId, false, -1, false, OnlyFutureDates, cToken);
var isColumnEmpty = GetEmptyColumnIndexes(result);
var columnTitles = new List<string>();
var columnIndexes = new List<int>();
for (int i = 1; i <= 7; i++)
{
if (!isColumnEmpty[i])
{
columnTitles.Add(Constants.DowLocal[i]);
columnIndexes.Add(i);
}
}
Paragraph oPara1 = oDoc.Content.Paragraphs.Add();
oPara1.Range.Text = "Расписание СГОАН (" + teacher.FIO + ")";
oPara1.Range.Font.Bold = 0;
oPara1.Range.Font.Size = 10;
oPara1.Range.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
oPara1.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
oPara1.SpaceAfter = 0;
oPara1.Range.InsertParagraphAfter();
Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
var dowCount = isColumnEmpty.Count(dow => !dow.Value);
Table oTable = oDoc.Tables.Add(wrdRng, 1 + result.Count, 1 + dowCount);
oTable.Borders.Enable = 1;
oTable.Range.ParagraphFormat.SpaceAfter = 0.0F;
oTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oTable.Range.Font.Size = 10;
oTable.Range.Font.Bold = 0;
oTable.Cell(1, 1).Range.Text = "Время";
oTable.Cell(1, 1).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Columns[1].Width = oWord.CentimetersToPoints(2.44f);
float colWidth = 16.3F / dowCount;
for (int i = 0; i < dowCount; i++)
{
oTable.Columns[i + 2].Width = oWord.CentimetersToPoints(colWidth);
oTable.Cell(1, i + 2).Range.Text = columnTitles[i];
oTable.Cell(1, i + 2).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
}
for (int i = 0; i < result.Count; i++)
{
oTable.Cell(2 + i, 1).Range.Text = result[i].Time;
oTable.Cell(2 + i, 1).Range.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Cell(2 + i, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
for (int j = 0; j < dowCount; j++)
{
var dowIndex = columnIndexes[j];
switch (dowIndex)
{
case 1:
oTable.Cell(2 + i, 2 + j).Range.Text = result[i].MonLessons;
break;
case 2:
oTable.Cell(2 + i, 2 + j).Range.Text = result[i].TueLessons;
break;
case 3:
oTable.Cell(2 + i, 2 + j).Range.Text = result[i].WedLessons;
break;
case 4:
oTable.Cell(2 + i, 2 + j).Range.Text = result[i].ThuLessons;
break;
case 5:
oTable.Cell(2 + i, 2 + j).Range.Text = result[i].FriLessons;
break;
case 6:
oTable.Cell(2 + i, 2 + j).Range.Text = result[i].SatLessons;
break;
case 7:
oTable.Cell(2 + i, 2 + j).Range.Text = result[i].SunLessons;
//.........这里部分代码省略.........
示例10: ExportTypeSequenceInfoByFaculty
public static void ExportTypeSequenceInfoByFaculty(ScheduleRepository repo)
{
var faculties = repo.Faculties.GetAllFaculties().OrderBy(f => f.SortingOrder).ToList();
object oMissing = Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
_Application oWord = new Application { Visible = true };
_Document oDoc = oWord.Documents.Add();
oDoc.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
for (int i = 0; i < faculties.Count; i++)
{
var faculty = faculties[i];
AddPara(oDoc, faculty.Name, 14);
var facultyGroups =
repo.GroupsInFaculties
.GetFiltredGroupsInFaculty(gif => gif.Faculty.FacultyId == faculty.FacultyId)
.Select(gif => gif.StudentGroup)
.ToList();
for (int j = 0; j < facultyGroups.Count; j++)
{
var studentGroup = facultyGroups[j];
AddPara(oDoc, studentGroup.Name);
var studentIds = repo
.StudentsInGroups
.GetFiltredStudentsInGroups(sig => sig.StudentGroup.StudentGroupId == studentGroup.StudentGroupId && !sig.Student.Expelled)
.ToList()
.Select(stig => stig.Student.StudentId);
var groupsListIds = repo
.StudentsInGroups
.GetFiltredStudentsInGroups(sig => studentIds.Contains(sig.Student.StudentId))
.ToList()
.Select(stig => stig.StudentGroup.StudentGroupId)
.Distinct()
.ToList();
var groupDisciplines =
repo.Disciplines.GetFiltredDisciplines(
d => groupsListIds.Contains(d.StudentGroup.StudentGroupId)).ToList();
Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Table oTable = oDoc.Tables.Add(wrdRng, groupDisciplines.Count+1, 2);
oTable.Borders.Enable = 1;
oTable.Range.ParagraphFormat.SpaceAfter = 0.0F;
oTable.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oTable.Range.Font.Size = 14;
oTable.Range.Font.Bold = 0;
oTable.Cell(1, 1).Range.Text = "Дисциплина";
oTable.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
oTable.Cell(1, 2).Range.Text = "Последовательность занятий";
oTable.Cell(1, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
for (int k = 0; k < groupDisciplines.Count; k++)
{
var discipline = groupDisciplines[k];
oTable.Cell(k + 2, 1).Range.Text = discipline.Name;
oTable.Cell(k + 2, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
var sequence = (discipline.AuditoriumHours != 0 && string.IsNullOrEmpty(discipline.TypeSequence))
? "Нет данных"
: discipline.TypeSequence;
oTable.Cell(k + 2, 2).Range.Text = sequence;
oTable.Cell(k + 2, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
}
}
AddPara(oDoc, "", 1);
Range wordRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Table legendTable = oDoc.Tables.Add(wordRng, 1 + Constants.LessonTypeLongAbbreviation.Count, 2);
legendTable.Borders.Enable = 1;
legendTable.Cell(1, 1).Range.Text = "Код";
legendTable.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
legendTable.Cell(1, 2).Range.Text = "Вид занятия";
legendTable.Cell(1, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
var lineNumber = 2;
foreach (var kvp in Constants.LessonTypeLongAbbreviation.OrderBy(p => p.Key))
{
legendTable.Cell(lineNumber, 1).Range.Text = kvp.Key.ToString();
//.........这里部分代码省略.........
示例11: ExportCultureDates
public static void ExportCultureDates(ScheduleRepository repo)
{
var discs = repo.Disciplines.GetFiltredDisciplines(d => d.Name.Contains("изическ")).ToList();
discs.Sort((x, y) =>
{
var teacherFIO1 = "";
var tfd1 =
repo.TeacherForDisciplines.GetFirstFiltredTeacherForDiscipline(
tefd => tefd.Discipline.DisciplineId == x.DisciplineId);
if (tfd1 != null)
{
teacherFIO1 = tfd1.Teacher.FIO;
}
var teacherFIO2 = "";
var tfd2 =
repo.TeacherForDisciplines.GetFirstFiltredTeacherForDiscipline(
tefd => tefd.Discipline.DisciplineId == y.DisciplineId);
if (tfd2 != null)
{
teacherFIO2 = tfd2.Teacher.FIO;
}
if ((teacherFIO1 == "") || (teacherFIO2 == ""))
{
return String.CompareOrdinal(teacherFIO1, teacherFIO2);
}
if (teacherFIO1 == teacherFIO2)
{
return tfd1.Discipline.StudentGroup.Name == tfd2.Discipline.StudentGroup.Name ?
String.CompareOrdinal(tfd1.Discipline.Name, tfd2.Discipline.Name) :
String.CompareOrdinal(tfd1.Discipline.StudentGroup.Name, tfd2.Discipline.StudentGroup.Name);
}
return String.Compare(teacherFIO1, teacherFIO2, StringComparison.Ordinal);
});
object oMissing = Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
_Application oWord = new Application { Visible = true };
_Document oDoc = oWord.Documents.Add();
oDoc.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
TeacherForDiscipline tfd = null;
for (int i = 0; i < discs.Count; i++)
{
var teacherFIO = "";
tfd =
repo.TeacherForDisciplines.GetFirstFiltredTeacherForDiscipline(
tefd => tefd.Discipline.DisciplineId == discs[i].DisciplineId);
if (tfd != null)
{
teacherFIO = tfd.Teacher.FIO;
}
Paragraph oPara1 = oDoc.Content.Paragraphs.Add();
oPara1.Range.Text = teacherFIO + " " +
discs[i].Name + " " +
discs[i].PracticalHours.ToString() + " " +
((Constants.Attestation.ContainsKey(discs[i].Attestation)) ? Constants.Attestation[discs[i].Attestation] : "") + " " +
discs[i].StudentGroup.Name;
oPara1.Range.Font.Bold = 0;
oPara1.Range.Font.Size = 10;
oPara1.Range.ParagraphFormat.LineSpacingRule =
WdLineSpacing.wdLineSpaceSingle;
oPara1.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
oPara1.SpaceAfter = 0;
oPara1.Range.InsertParagraphAfter();
if (tfd == null)
{
continue;
}
var tfd1 = tfd;
var discLessons =
repo.Lessons.GetFiltredLessons(
l =>
l.TeacherForDiscipline.TeacherForDisciplineId == tfd1.TeacherForDisciplineId &&
(l.State == 1 || l.State == 2))
.ToList();
discLessons = discLessons.OrderBy(l => l.Calendar.Date).ToList();
Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Table oTable = oDoc.Tables.Add(wrdRng, discLessons.Count, 2);
oTable.Borders.Enable = 1;
oTable.Range.ParagraphFormat.SpaceAfter = 0.0F;
//.........这里部分代码省略.........
示例12: saveDocx
private int saveDocx(object filePath)
{
Microsoft.Office.Interop.Word.Application wrdApp;
Object oMissing = System.Reflection.Missing.Value;
Object oEndOfDoc = "\\endofdoc";
wrdApp = new Microsoft.Office.Interop.Word.Application();
wrdApp.Visible = false; //執行過程不在畫面上開啟 Word
Microsoft.Office.Interop.Word._Document myDoc;
myDoc = wrdApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
myDoc.PageSetup.TopMargin = wrdApp.CentimetersToPoints(float.Parse("1"));
myDoc.PageSetup.BottomMargin = wrdApp.CentimetersToPoints(float.Parse("1"));
myDoc.PageSetup.LeftMargin = wrdApp.CentimetersToPoints(float.Parse("1"));
myDoc.PageSetup.RightMargin = wrdApp.CentimetersToPoints(float.Parse("1"));
Microsoft.Office.Interop.Word.Table myTable;
Microsoft.Office.Interop.Word.Range wrdRng = myDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
int dataCount = dataList.Count;
if (dataCount % 3 == 0)
{
myTable = myDoc.Tables.Add(wrdRng, dataCount, 3, ref oMissing, ref oMissing);// 新增表格
}
else
{
dataCount = dataCount + (3 - (dataCount % 3));
myTable = myDoc.Tables.Add(wrdRng, dataCount, 3, ref oMissing, ref oMissing);// 新增表格
}
myTable.Select();
wrdApp.Selection.Tables[1].Rows.Alignment = word.WdRowAlignment.wdAlignRowCenter; // 表格置中
//設定表格寬高
myTable.Rows.Height = (float)(88.4 / pixelToMm);
myTable.Cell(1, 1).Column.SetWidth((float)(152.5 / pixelToMm), 0);
myTable.Cell(1, 2).Column.SetWidth((float)(12.5 / pixelToMm), 0);
myTable.Cell(1, 3).Column.SetWidth((float)(12.5 / pixelToMm), 0);
for (int i = 0; i < dataList.Count; i++)
{
myTable.Range.Font.Name = "標楷體";
myTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
myTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
//設定表格內直書
myTable.Cell(i + 1, 2).Range.Orientation = word.WdTextOrientation.wdTextOrientationVerticalFarEast;
myTable.Cell(i + 1, 3).Range.Orientation = word.WdTextOrientation.wdTextOrientationVerticalFarEast;
if (dataList[i].dataIsEmpty == true)
{
continue;
}
//填入表格內文字
myTable.Cell(i + 1, 2).Range.Text = dataList[i].des;
myTable.Cell(i + 1, 3).Range.Text = dataList[i].title;
//剪貼簿複製圖片過去
if (dataList[i].imageData == null)
{
continue;
}
Microsoft.Office.Interop.Word.Range a = myDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Clipboard.SetImage(dataList[i].imageData);
myTable.Cell(i + 1, 1).Range.InsertParagraphAfter();
myTable.Cell(i + 1, 1).Range.Select();
myTable.Cell(i + 1, 1).Range.Paste();
//設定表格置中
myTable.Cell(i + 1, 1).VerticalAlignment = word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
myTable.Cell(i + 1, 1).Range.ParagraphFormat.Alignment = word.WdParagraphAlignment.wdAlignParagraphCenter;
}
Object oFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument; //格式
myDoc.SaveAs(ref filePath, ref oFormat,
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 oFalse = false;
myDoc.Close(ref oFalse, ref oMissing, ref oMissing);
return 1;
}
示例13: ExportWord
/// <summary>
/// 导出
/// </summary>
/// <param name="overTimeList"></param>
/// <param name="fileName"></param>
public void ExportWord(List<OverTimeModel> overTimeList, string fileName)
{
Microsoft.Office.Interop.Word.Application app = null;
Microsoft.Office.Interop.Word.Document doc = null;
try
{
int rows = overTimeList.Count + 4;//表格行数
int cols = 6;//表格列数
object oMissing = System.Reflection.Missing.Value;
object Visible = true;
app = new Microsoft.Office.Interop.Word.Application();//创建Word应用程序
doc = app.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref Visible);//添加Word文档
//设置页边距
doc.PageSetup.LeftMargin = 71;
doc.PageSetup.RightMargin = 71;
doc.PageSetup.TopMargin = 56.8f;
doc.PageSetup.BottomMargin = 42.6f;
//设置页眉页脚为1cm
app.ActiveDocument.PageSetup.HeaderDistance = app.CentimetersToPoints(1f);
app.ActiveDocument.PageSetup.FooterDistance = app.CentimetersToPoints(1f);
//设置页眉内容
string filename = System.Windows.Forms.Application.StartupPath + "\\logo.png";//设置图片路径
object linkToFile = false;//定义该插入的图片是否为外部链接
object saveWithDocument = true;//定义要插入的图片是否随Word文档一起保存
object headerFooterRange;//在Word中插入的位置
foreach (Section section in doc.Sections)
{
foreach (HeaderFooter headerFooter in section.Headers)
{
headerFooterRange = headerFooter.Range;//在页眉中插入
headerFooter.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;//设置图片位置为居左
doc.InlineShapes.AddPicture(filename, ref linkToFile, ref saveWithDocument, ref headerFooterRange);//插入图片
}
}
//输入大标题加粗加大字号水平居中
app.Selection.Font.Bold = 700;
app.Selection.Font.Size = 15;
app.Selection.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
app.Selection.Text = "加班申请单";
//换行添加表格
object line = WdUnits.wdLine;
app.Selection.MoveDown(ref line, oMissing, oMissing);
app.Selection.TypeParagraph();//换行
Range range = app.Selection.Range;
Table table = app.Selection.Tables.Add(range, rows, cols, ref oMissing, ref oMissing);
table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
table.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;
//设置表格的字体大小
table.Range.Font.Size = 10.5f;
table.Range.Font.Bold = 0;
//设置表格中的第二行为加粗
table.Rows[2].Range.Font.Bold = 700;
//设置表格的行高
table.Rows.Height = 25f;
table.Rows.HeightRule = WdRowHeightRule.wdRowHeightExactly;
//设置表格列的宽度
table.Columns[1].Width = 75f;
table.Columns[2].Width = 95f;
table.Columns[3].Width = 95f;
table.Columns[4].Width = 95f;
table.Columns[5].Width = 70f;
table.Columns[6].Width = 85f;
//设置Table居中
table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;
//设置第一行
int rowIndex = 1;
table.Cell(rowIndex, 1).Range.Text = "申请人";
//table.Cell(rowIndex, 2).Range.Text = txtSqr.Text;
this.txtSqr.Dispatcher.Invoke(new Action(() => table.Cell(rowIndex, 2).Range.Text = this.txtSqr.Text));
table.Cell(rowIndex, 3).Range.Text = "所属部门";
//table.Cell(rowIndex, 4).Range.Text = txtSsbm.Text;
this.txtSsbm.Dispatcher.Invoke(new Action(() => table.Cell(rowIndex, 4).Range.Text = this.txtSsbm.Text));
table.Cell(rowIndex, 5).Range.Text = "申请时间";
//table.Cell(rowIndex, 6).Range.Text = dpSqrq.Text;
this.dpSqrq.Dispatcher.Invoke(new Action(() => table.Cell(rowIndex, 6).Range.Text = this.dpSqrq.Text));
//设置第二行
rowIndex = 2;
table.Cell(rowIndex, 1).Range.Text = "姓名";
table.Cell(rowIndex, 2).Range.Text = "加班类型";
table.Cell(rowIndex, 3).Range.Text = "加班时间起";
table.Cell(rowIndex, 4).Range.Text = "加班时间止";
//.........这里部分代码省略.........
示例14: Output
/// <summary>
/// Вывод полученной информации в файл Word
/// </summary>
/// <param name="rapporteurs"> Список, который нужно вывести </param>
public static void Output(List<Rapporteur> rapporteurs)
{
if (rapporteurs.Count == 0)
return;
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc";
//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);
Object start = Type.Missing;
Object end = Type.Missing;
Word.Range wordrange = oDoc.Range(ref start, ref end);
//Устанавливаем поля в документе по 1,5 см
wordrange.PageSetup.LeftMargin = oWord.CentimetersToPoints((float)1.5);
wordrange.PageSetup.RightMargin = oWord.CentimetersToPoints((float)1.5);
wordrange.PageSetup.BottomMargin = oWord.CentimetersToPoints((float)1.5);
wordrange.PageSetup.TopMargin = oWord.CentimetersToPoints((float)1.5);
//Insert a paragraph at the beginning of the document.
Word.Paragraph oPara1;
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Text = "ПЕРЕЧЕНЬ АВТОРОВ";
Word.Range wrdRng1 = oDoc.Paragraphs[1].Range;
//Форматирование документа
wrdRng1.Font.Size = 14;
wrdRng1.Font.Name = "Courier New";
wrdRng1.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
wrdRng1.Bold = 1;
oPara1.Range.InsertParagraphAfter();
object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
Word.Range wrdRng = oDoc.Paragraphs[2].Range;
wrdRng.Font.Size = 12;
wrdRng.Font.Name = "Courier New";
wrdRng.Bold = 0;
wrdRng.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; //wdAlignParagraphJustify;
//Переменная, нужная для подсчета длины: длина фамилии с инициалами + длина чисел
int countStr = 0;
for (int i = 0; i < rapporteurs.Count; i++)
{
int rapporteursNumberCount = rapporteurs[i].Number.Count;
wrdRng.ParagraphFormat.SpaceAfter = 6;
countStr += rapporteurs[i].Name.Length;
wrdRng.InsertAfter(rapporteurs[i].Name);
if (rapporteursNumberCount == 1)
countStr += rapporteurs[i].Number[0].Length;
else
{
for (int k = 0; k < rapporteursNumberCount - 1; k++)
countStr += rapporteurs[i].Number[k].Length + 2;
countStr += rapporteurs[i].Number[rapporteursNumberCount - 1].Length;
}
int countP = 31 - countStr;
string p = "";
for (int k = 0; k < countP; k++)
p += ".";
wrdRng.InsertAfter(p);
for (int k = 0; k < rapporteursNumberCount - 1; k++)
wrdRng.InsertAfter(rapporteurs[i].Number[k] + ", ");
wrdRng.InsertAfter(rapporteurs[i].Number[rapporteurs[i].Number.Count - 1]);
wrdRng.InsertParagraphAfter();
countP = 0;
countStr = 0;
}
}
示例15: SaveAsWordDocument
private void SaveAsWordDocument(int facultyFilter)
{
DateTime beginSessionDate, endSessionDate;
DetectSessionDates(out beginSessionDate, out endSessionDate);
object oMissing = Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
_Application oWord = new Application();
oWord.Visible = true;
_Document oDoc =
oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(1);
oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1);
List<Faculty> faculties;
if (facultyFilter != -1)
{
var onefaculty = _repo.Faculties.GetFaculty((int)FacultyList.SelectedValue);
faculties = oneFaculty == null ?
_repo.Faculties.GetAllFaculties().OrderBy(f => f.SortingOrder).ToList() :
new List<Faculty> {onefaculty};
}
else
{
faculties = _repo.Faculties.GetAllFaculties().OrderBy(f => f.SortingOrder).ToList();
}
foreach (var faculty in faculties)
{
/*
var groupIds = new List<int>();
foreach (var group in Constants.facultyGroups.ElementAt(facCounter).Value)
{
var groupId = _repo.FindStudentGroup(group);
if (groupId != null)
{
groupIds.Add(groupId.StudentGroupId);
}
}*/
var localFaculty = faculty;
var groupIds = _repo
.GroupsInFaculties
.GetFiltredGroupsInFaculty(gif => gif.Faculty.FacultyId == localFaculty.FacultyId)
.Select(gif => gif.StudentGroup.StudentGroupId)
.ToList();
var facultyExams = _repo.Exams.GetFacultyExams(_repo, groupIds);
facultyExams = facultyExams
.OrderBy(fe => fe.Key)
.ToDictionary(keyItem => keyItem.Key, valueItem => valueItem.Value);
Paragraph oPara1 =
oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Font.Size = 24;
oPara1.Format.LineSpacing = oWord.LinesToPoints(1);
oPara1.Range.Text = "Расписание";
oPara1.Format.SpaceAfter = 0;
oPara1.Range.InsertParagraphAfter();
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Font.Size = 14;
oPara1.Format.SpaceAfter = 0;
if (beginSessionDate.Month < 3)
{
var startYear = beginSessionDate.Year - 1;
oPara1.Range.Text = "зимней сессии " + startYear + "-" + (startYear + 1) + " учебного года" +
Environment.NewLine +
faculty.Name;
}
else
{
var startYear = beginSessionDate.Year - 1;
oPara1.Range.Text = "летней сессии " + startYear + "-" + (startYear + 1) + " учебного года" +
Environment.NewLine +
faculty.Name;
}
oPara1.Range.InsertParagraphAfter();
Shape signBox = oDoc.Shapes
.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 350, 15, 200, 75, oPara1.Range);
signBox.Line.Visible = MsoTriState.msoFalse;
signBox.TextFrame.ContainingRange.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphRight;
var prorUchRabNameOption = _repo.ConfigOptions.GetFirstFiltredConfigOption(co => co.Key == "Проректор по учебной работе");
var prorUchRabName = (prorUchRabNameOption == null) ? "" : prorUchRabNameOption.Value;
signBox.TextFrame.ContainingRange.InsertAfter("«УТВЕРЖДАЮ»");
signBox.TextFrame.ContainingRange.InsertParagraphAfter();
//.........这里部分代码省略.........