Hi
I have a question pertaining to the styling of lists. I used the following code (Sample A)to create a list in a generated document. The output looked exactally the way I wanted to. The issue was when a end user then copy and pasted the output to another word document (a common occurance), it lost its formatting. From doing some research it seems that the soruce of the problem is that the destination document had conflicting styles.
So I thought the way to fix it was to create a List Style, but I have been having issues trying to use List Styles to look like the original. Sample B shows how I am now starting the list.
Question 1) Do you think I am going about solving the cut and paste issue the right way, with trying to assign a Style to the list
Question 2) If so how can I use List Styles to make it look like it was in my original Template based approach?
Thanks for your help:
Sample A
public static List CreateCompensationStructureList(Document document)
{
List list = document.Lists.Add(ListTemplate.OutlineHeadingsLegal);
ListLevel level1 = list.ListLevels[0];
level1.NumberFormat = "\x0000.0";
level1.NumberPosition = 0;
level1.TabPosition = AsposeUtils.PointsInInch(0.45d);
level1.TextPosition = AsposeUtils.PointsInInch(0.45d);
ListLevel level2 = list.ListLevels[1];
level2.NumberStyle = NumberStyle.LeadingZero;
level2.NumberFormat = "\x0000.\x0001";
level2.NumberPosition = AsposeUtils.PointsInInch(0);
level2.TabPosition = AsposeUtils.PointsInInch(0.45d);
level2.TextPosition = AsposeUtils.PointsInInch(0.45d);
ListLevel level3 = list.ListLevels[2];
level3.NumberStyle = NumberStyle.LeadingZero;
level3.NumberFormat = "\x0000.\x0001.\x0002";
level3.NumberPosition = AsposeUtils.PointsInInch(0.45d);
level3.TabPosition = AsposeUtils.PointsInInch(1.05);
level3.TextPosition = AsposeUtils.PointsInInch(1.05);
ListLevel level4 = list.ListLevels[3];
level4.NumberStyle = NumberStyle.LowercaseRoman;
level4.NumberFormat = "(\x0003)";
level4.NumberPosition = AsposeUtils.PointsInInch(1.05d);
level4.TabPosition = AsposeUtils.PointsInInch(1.65);
level4.TextPosition = AsposeUtils.PointsInInch(1.65);
ListLevel level5 = list.ListLevels[4];
level5.NumberStyle = NumberStyle.LowercaseLetter;
level5.NumberFormat = "(\x0004)";
level5.NumberPosition = AsposeUtils.PointsInInch(1.65d);
level5.TabPosition = AsposeUtils.PointsInInch(2.25);
level5.TextPosition = AsposeUtils.PointsInInch(2.25);
ListLevel level6 = list.ListLevels[5];
level6.NumberStyle = NumberStyle.LowercaseRoman;
level6.NumberFormat = "(\x0004.\x0005)";
level6.NumberPosition = AsposeUtils.PointsInInch(2.25d);
level6.TabPosition = AsposeUtils.PointsInInch(2.85);
level6.TextPosition = AsposeUtils.PointsInInch(2.85);
for (int i = 6; i < list.ListLevels.Count; i++)
{
ListLevel level = list.ListLevels[i];
level.NumberPosition = AsposeUtils.PointsInInch(1.05d);
level.TabPosition = AsposeUtils.PointsInInch(1.65);
level.TextPosition = AsposeUtils.PointsInInch(1.65);
}
return list;
}
Sample B
#region CreateCompensationStructureList
private static Style GetCompensationStructureListStyle(Document doc)
{
string styleName = "CompensationStructureList";
bool styleExists = false;
foreach (Style style in doc.Styles)
{
if (style.Type == StyleType.List && style.Name == styleName)
{
styleExists = true;
break;
}
}
if (styleExists)
{
return doc.Styles[styleName];
}
else
{
Style listStyle = doc.Styles.Add(StyleType.List, styleName);
List list = listStyle.List;
// Check some basic rules about the list that defines a list style.
Debug.Assert(list.IsListStyleDefinition);
Debug.Assert(!list.IsListStyleReference);
Debug.Assert(list.IsMultiLevel);
Debug.Assert(listStyle == list.Style);
ListLevel level1 = list.ListLevels[0];
level1.NumberFormat = "\x0000.0";
level1.NumberPosition = 0;
level1.TabPosition = AsposeUtils.PointsInInch(0.45d);
level1.TextPosition = AsposeUtils.PointsInInch(0.45d);
ListLevel level2 = list.ListLevels[1];
level2.NumberStyle = NumberStyle.LeadingZero;
level2.NumberFormat = "\x0000.\x0001";
level2.NumberPosition = AsposeUtils.PointsInInch(0);
level2.TabPosition = AsposeUtils.PointsInInch(0.45d);
level2.TextPosition = AsposeUtils.PointsInInch(0.45d);
ListLevel level3 = list.ListLevels[2];
level3.NumberStyle = NumberStyle.LeadingZero;
level3.NumberFormat = "\x0000.\x0001.\x0002";
level3.NumberPosition = AsposeUtils.PointsInInch(0.45d);
level3.TabPosition = AsposeUtils.PointsInInch(1.05);
level3.TextPosition = AsposeUtils.PointsInInch(1.05);
ListLevel level4 = list.ListLevels[3];
level4.NumberStyle = NumberStyle.LowercaseRoman;
level4.NumberFormat = "(\x0003)";
level4.NumberPosition = AsposeUtils.PointsInInch(1.05d);
level4.TabPosition = AsposeUtils.PointsInInch(1.65);
level4.TextPosition = AsposeUtils.PointsInInch(1.65);
ListLevel level5 = list.ListLevels[4];
level5.NumberStyle = NumberStyle.LowercaseLetter;
level5.NumberFormat = "(\x0004)";
level5.NumberPosition = AsposeUtils.PointsInInch(1.65d);
level5.TabPosition = AsposeUtils.PointsInInch(2.25);
level5.TextPosition = AsposeUtils.PointsInInch(2.25);
for (int i = 5; i < list.ListLevels.Count; i++)
{
ListLevel level = list.ListLevels[i];
level.NumberPosition = AsposeUtils.PointsInInch(1.05d);
level.TabPosition = AsposeUtils.PointsInInch(1.65);
level.TextPosition = AsposeUtils.PointsInInch(1.65);
}
return listStyle;
}
}
public static List CreateCompensationStructureList(Document document)
{
Style listStyle = GetCompensationStructureListStyle(document);
List list = document.Lists.Add(listStyle);
return list;
}
#endregion // CreateCompensationStructureList