How can i create nested bulleted/Ordered lists with Novacode for docx?
I've done some research but couldn't find anything, any help is appreciated.
Hope it's not too late, I've just figured it out a couple hours ago
class Program
{
static void Main(string[] args)
{
string docPath = "PATH TO YOUR OUTPUT WORD DOCUMENT" ;
var doc = DocX.Create(docPath);
var l = doc.AddList("Item #1", 0, ListItemType.Bulleted, 0);
doc.AddListItem(l, "Item #2");
doc.InsertList(l);
doc.Save();
}
}
You should use the indent-level (parameter 2 of DocX.AddList(...) and parameter 3 of DocX.AddListItem(...))
DocX doc = DocX.Create("filename.docx");
List list = doc.AddList("item 1", 0, ListItemType.Numbered);
doc.AddListItem(list, "item 2", 1);
doc.AddListItem(list, "item 3", 1);
doc.AddListItem(list, "item 4", 2);
doc.AddListItem(list, "item 5", 2);
doc.AddListItem(list, "item 6", 1);
doc.AddListItem(list, "item 7", 0);
doc.AddListItem(list, "item 8", 2);
doc.InsertList(list);
This produces:
Related
I am putting some results together in a nested list (with arrays). The expected results must be EXACTLY as follows:
{
"item1": "TEXT",
"item2": "MORE TEXT",
"item3": [
"STILL TEXT"
],
"item4": [
"TEXT AGAIN"
],
"values": [
{
"start": 0,
"end": 99
}
]
}
I put all my results together like this:
listToJson <- c(list(item1 = "TEXT",
item2 = "MORE TEXT",
item3 = "STILL TEXT",
item4 = "TEXT AGAIN",
values = list(start = 99,
end = 0)))
write_json(listToJson, path = "test.json", auto_unbox = TRUE , null = "null")
The problem is that the results doesn't have array elements (see below). item3 and item4 should be arrays. How can I change my code to get the expected results in that exact format?
{
"item1":"TEXT",
"item2":"MORE TEXT",
"item3":"STILL TEXT",
"item4":"TEXT AGAIN",
"values":{
"start":99,
"end":0}
}
You can just use as.array for those specific items.
library(jsonlite)
listToJson <- c(
list(
item1 = "TEXT",
item2 = "MORE TEXT",
item3 = as.array("STILL TEXT"),
item4 = as.array("TEXT AGAIN"),
values = as.array(list(start = 99,
end = 0))
)
)
write_json(listToJson, path = "test.json", auto_unbox = TRUE , null = "null")
Output
{
"item1":"TEXT",
"item2":"MORE TEXT",
"item3":[
"STILL TEXT"
],
"item4":[
"TEXT AGAIN"
],
"values":[
{
"start":0,
"end":99
}
]
}
I am working on an app which requires TreeView.
I'm able to generate the Treeview but facing issue with dynamically updating the treeview based on underlying dataset change.
Classes:
data class Channels(
val channel: Channel? = null
)
data class Channel(
val id: String? = null,
val name: String? = null,
val parentChannelId: String? = null
)
Data List :
var channels = observableListOf(
Channels(channel = Channel(id = "pc1", name = "P Channel 1")),
Channels(channel = Channel(id = "c11", name = "Child 1-1", parentChannelId = "pc1")),
Channels(channel = Channel(id = "c12", name = "Child 1-2", parentChannelId = "pc1")),
Channels(channel = Channel(id = "c121", name = "Child 1-2-1", parentChannelId = "c12")),
Channels(channel = Channel(id = "c111", name = "Child 1-1-1", parentChannelId = "c11")),
Channels(
channel = Channel(
id = "c1111",
name = "Child 1-1-1-1",
parentChannelId = "c111"
)
),
Channels(channel = Channel(id = "pc2", name = "P Channel 2")),
Channels(channel = Channel(id = "pc3", name = "P Channel 3")),
Channels(channel = Channel(id = "c31", name = "Child 3-1", parentChannelId = "pc3"))
)
Treeview :
treeview<Channels> {
isShowRoot = false
root = TreeItem()
cellFormat { text = it.channel?.name }
populate { parent ->
if (parent == root) channels.filter {
it.channel?.parentChannelId == null
} else channels.filter {
it.channel?.parentChannelId == parent.value?.channel?.id
}
}
}
Now when I modify the channels list, treeview doesn't gets updated.
I've been stuck on this since 3-4 days.
Please help.
I am using ASPOSE Slides in my project to perform a PPT task. I want to change my table header background-color but I have not found any solutions in Aspose forum for it. Can anybody provide me with the solution?
ISlide sld = press.Slides[0];
double[] dblCols = { 250, 250};
double[] dblRows = { 70, 70, 70,70 };
// Add table shape to slide
ITable tbl = sld.Shapes.AddTable(100, 100, dblCols, dblRows);
tbl[0, 1].TextFrame.Text = "some text";
tbl[0, 2].TextFrame.Text = "some text";
tbl[0, 3].TextFrame.Text = "some text";
tbl[0, 3].BorderBottom.FillFormat.FillType = FillType.Solid;
tbl[0, 3].FillFormat.SolidFillColor.BackgroundColor = Color.Blue;
tbl[0,3].BorderBottom.Width = 2;
Portion portion = (Portion)tbl[0, 1].TextFrame.Paragraphs[0].Portions[0];
portion.PortionFormat.FillFormat.FillType = FillType.Solid;
portion.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
}
I have observed you requirements related to setting table header background. Please try using following sample code that has example of setting fill color for one of header row cell. You can replicate the same for other cells too.
public static void TestTableBackground()
{
Presentation press = new Presentation();
ISlide sld = press.Slides[0];
double[] dblCols = { 250, 250 };
double[] dblRows = { 70, 70, 70, 70 };
// Add table shape to slide
ITable tbl = sld.Shapes.AddTable(100, 100, dblCols, dblRows);
tbl[0, 1].TextFrame.Text = "some text";
tbl[0, 2].TextFrame.Text = "some text";
tbl[0, 3].TextFrame.Text = "some text";
tbl[0, 0].FillFormat.FillType = FillType.Solid;
tbl[0, 0].FillFormat.SolidFillColor.Color = Color.Blue;
Portion portion = (Portion)tbl[0, 1].TextFrame.Paragraphs[0].Portions[0];
portion.PortionFormat.FillFormat.FillType = FillType.Solid;
portion.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
press.Save(#"C:\Aspose Data\TableFormat.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
I am working as Support developer/ Evangelist at Aspose.
I have the below table,
Name Consumed
A Flavour 1
B Flavour 2
C Flavour 1
C Flavour 3
A Flavour 3
B Flavour 1
C Flavour 3
A Flavour 2
A Flavour 1
C Flavour 1
A Flavour 1
B Flavour 2
Where in the first column I have the name of the persons and in the second column the Flavour preferred by them. I want to generate the below table, with Flavours as columns and find the sum of the Flavours preferred by each person. I know the solution to these using SQL, however I'm looking for a solution using LINQ VB.Net.
Name Flavour 1 Flavour 2 Flavour 3
A 3 1 1
B 1 2 0
C 2 0 2
SQL Query for achieving the above result,
SELECT Name,
SUM(CASE WHEN Consumed='Flavour 1' THEN 1 ELSE 0) AS Flavour 1,
SUM(CASE WHEN Consumed='Flavour 2' THEN 1 ELSE 0) AS Flavour 2,
SUM(CASE WHEN Consumed='Flavour 3' THEN 1 ELSE 0) AS Flavour 3
GROUP BY Name
Below is the LINQ query,
Dim query = (From row In dtMain.AsEnumerable
Let Flavour_1 = IIf(row.Field(Of String)("Consumed") = "1", 1, 0)
Let Flavour_2 = IIf(row.Field(Of String)("Consumed") = "2", 1, 0)
Let Flavour_3 = IIf(row.Field(Of String)("Consumed") = "3", 1, 0)
Group row By Code = row.Field(Of String)("Name")
Into freq = Group Select .Code = Code, .Count = freq.Count()).ToList
My difficulty is in how to aggregate the temporary variables Flavour_1, Flavour_2 and Flavour_3 using SUM function and group it by Name.
Given the following data:
Dim table = {
New With { .Name = "A", .Consumed = "Flavor 1" },
New With { .Name = "B", .Consumed = "Flavor 2" },
New With { .Name = "C", .Consumed = "Flavor 1" },
New With { .Name = "C", .Consumed = "Flavor 3" },
New With { .Name = "A", .Consumed = "Flavor 3" },
New With { .Name = "B", .Consumed = "Flavor 1" },
New With { .Name = "C", .Consumed = "Flavor 3" },
New With { .Name = "A", .Consumed = "Flavor 2" },
New With { .Name = "A", .Consumed = "Flavor 1" },
New With { .Name = "C", .Consumed = "Flavor 1" },
New With { .Name = "A", .Consumed = "Flavor 1" },
New With { .Name = "B", .Consumed = "Flavor 2" }
}
the query you're looking for is:
Dim result = From e In table
Group e By Name = e.Name Into g = group
Select New With
{
.Name = Name,
.Flavour1 = g.Count(Function(x) x.Consumed = "Flavor 1"),
.Flavour2 = g.Count(Function(x) x.Consumed = "Flavor 2"),
.Flavour3 = g.Count(Function(x) x.Consumed = "Flavor 3")
}
It's quite similar to your SQL (group, then aggregate), but you use Count instead of SUM.
You don't need a Let.
I am creating a 3d chart using Microsoft Chart controls. Here is the image:
(source: highoncoding.com)
I want to show the point on the top of each bar graph. Like for Exam 1 on top of bar chart it should show 2 (as in 2 points) etc.
Here is the code:
private void BindData() {
var exams = new List<Exam>()
{
new Exam() { Name = "Exam 1", Point = 10 },
new Exam() { Name = "Exam 2", Point = 12 },
new Exam() { Name = "Exam 3", Point = 15 },
new Exam() { Name = "Exam 4", Point = 2 }
};
var series = ExamsChart.Series["ExamSeries"];
series.YValueMembers = "Point";
series.XValueMember = "Name";
//series.MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Circle;
//series.MarkerSize = 20;
//series.LegendText = "hellow";
//series.Label = "something";
var chartAreas = ExamsChart.ChartAreas["ChartArea1"];
ExamsChart.DataSource = exams;
ExamsChart.DataBind();
}
and here is the html code:
<asp:Chart ID="ExamsChart" Width="600" Height="320" runat="server">
<Titles>
<asp:Title Text="Exam Report" />
</Titles>
<Series>
<asp:Series Name="ExamSeries" ChartType="Column">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<Area3DStyle Enable3D="true" WallWidth="10" />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
UPDATE:
Here is the answer:
foreach (var exam in exams) {
var point = new DataPoint();
point.SetValueXY(exam.Name, exam.Point);
point.Label = exam.Name;
series.Points.Add(point);
}
Directly from the MS chart samples:
// Show data points values as labels
chart1.Series["Series1"].IsValueShownAsLabel = true;
// Set data point label
chart1.Series["Series1"].Points[2].Label = "My Point Label\nLabel Line #2";