Я могу получить все свойства, но не могу правильно установить FirstLineIndent.
Пример:
текущий результат:
- Это основной абзац li>
Ожидаемый результат:
- Это основной абзац
Это следующий абзац
На данный момент реализация выглядит следующим образом:
Код: Выделить всё
float GetFirstCharactorPosition(Document doc, string styleName)
{
try
{
// get the main style from the document styles
Style partStyle = doc.Styles((styleName));
// ho to start of the document
doc.Application.Selection.GoTo(WdGoToItem.wdGoToSection, WdGoToDirection.wdGoToFirst);
doc.ActiveWindow.Selection.HomeKey(WdUnits.wdStory);
// select first section
Section firstSec = doc.Sections(1);
// add paragraph at the last in the section
if ((firstSec.Range.Paragraphs.Last.Range.Characters.Count > 1))
firstSec.Range.InsertParagraphAfter();
// get last paragraph and apply main numbering style
Paragraph lastpara = doc.Paragraphs.Last;
Range rng = lastpara.Range.Duplicate;
rng.Style = partStyle;
rng.Text = "test";
//rng.Collapse(WdCollapseDirection.wdCollapseEnd);
//rng.MoveEnd(-1);
// get Text boundary
float firstCharPosition = System.Convert.ToSingle(rng.Information(WdInformation.wdHorizontalPositionRelativeToTextBoundary));
rng.Delete();
return firstCharPosition;
}
catch (Exception ex)
{
return ParagraphProps.LeftIndent;
}
finally
{
}
}
Если я запускаю то же самое в окне VBA, то оно выдает правильные 144.
Подробнее здесь: https://stackoverflow.com/questions/790 ... t-boundary
Мобильная версия