I use aspose word, create a datatable, add column, and then mail merge with the word template. But I find in the output, the column width is very different from the word template (e.g. the last column "last date of duty"), why?
The code is as follows:
DataTable tableOrders = new DataTable("Orders");
tableOrders.getColumns().add("rank");
tableOrders.getColumns().add("staffNo");
tableOrders.getColumns().add("name");
tableOrders.getColumns().add("idNo");
tableOrders.getColumns().add("nature");
tableOrders.getColumns().add("effDate");
tableOrders.getColumns().add("b4effDate");
while(i.hasNext()) {
Object[] rs = (Object[]) i.next();
String rank = rs[0]==null?"":rs[0].toString();
String staffNo = rs[1]==null?"":rs[1].toString();
String name = rs[2]==null?"":rs[2].toString();
String id_no = rs[3]==null?"":rs[3].toString();
String nature = rs[4]==null?"":rs[4].toString();
String effDate = rs[5]==null?"":(new SimpleDateFormat("yyyy-MM-dd")).format(rs[5]);
String lastDutyDate = rs[6]==null?"":(new SimpleDateFormat("yyyy-MM-dd")).format(rs[6]);
// Create the orders table.
tableOrders.getRows().add(rank, staffNo, name, id_no, nature, effDate, lastDutyDate);
}
doc.getMailMerge().executeWithRegions(tableOrders);
doc.getMailMerge().execute(new String[] {"currentDate"}, new String[] {sdf2.format(new Date())});
As I can see you are saving your output document as PDF. The problem might occur because your table layout is built improperly. But it is difficult to say without your a real document. You can post your question and attach your document in Aspose.Words support forum.
Also, you can try configuring your template to use Fixed Column Width.
Most likely, in your template, auto fit behavior is set to AutoFit to Contents and after executing mail merge column widths are adjusted according to the data.
Related
Would you let me know how to make the pivot table in excel using xlwings?
please give me the sample code
Thanks for your help
I have tried to find how to make it but I couldn't find it
Creating a PivotTable with xlwings is not currently straightforward, and requires the use of the .api to access the VBA functions.
An example to create a PivotTable using my mock data in a Table called Table1 of 3 columns of data with headers: "Colour", "Type", "Data".
# set the kwarg values for creating PivotTable
source_type = xw.constants.PivotTableSourceType.xlDatabase
source_data = wb.sheets["Sheet1"]["Table1[#All]"].api # cannot be of type Range or String
table_destination = wb.sheets["Sheet1"]["A20"].api # cannot be of type Range or String
table_name = "PTable1"
# create PivotTable
wb.api.PivotCaches().Create(SourceType=source_type,
SourceData=source_data).CreatePivotTable(
TableDestination=table_destination,
TableName=table_name)
pt = ws.api.PivotTables(table_name)
# Set Row Field (Rows) as Colour column of table
pt.PivotFields("Colour").Orientation = xw.constants.PivotFieldOrientation.xlRowField
# Set Column Field (Columns) as Type column of table
pt.PivotFields("Type").Orientation = xw.constants.PivotFieldOrientation.xlColumnField
# Set Data Field (Values) as Data
pt.AddDataField(pt.PivotFields("Data"),
# with name as "Sum of Data"
"Sum of Data",
# and calculation type as sum
xw.constants.ConsolidationFunction.xlSum)
Additional Detail
For reason of xlDatabase source_type, the VBA documentation can be found here
The parameters can be seen in the VBA documentation here. And this tutorial provides a detailed explanation of these, along with how to change this for different scenarios (dynamic range, in a new workbook, etc.); the guide gives a couple of additional changes to the formatting of the values, such as position of fields and number format.
The options for type of data calculation can be found here.
I have a database table that contains records, where each record has a criteria attribute. This criteria attribute can hold anywhere between 1-n criteria that I'd like to apply as filters on a different table.
This looks something like:
message.status:::eq:::submitted;;;message.count:::ge:::5
but could also be only
message.count:::ge:::5
What I'd like to do in DAX, is take that string and translate it into dynamic Filter attributes. So I somehow need to split the string based on ;;;, and then disect each section into the target (e.g. message[count]), the operator (e.g. ge --> >=) and the value (e.g. 5).
So in the end the following DAX snippet should be added to my Calculate 1 or more times:
example measure = CALCULATE(
COUNTROWS('message),
FILTER (
ALL('message'),
--- line below should be dynamically injected
message[count] >= 5
),
I'm struggling with how to create a loop (is this even possible in PBI?), and then even with a single string... hoe to filter based on this.
Thanks
You can try to build new table for splited message.
Table 2 =
var _splitby = ";;;"
var _string = SELECTCOLUMNS(ADDCOLUMNS(VALUES('Table'[message]),"pathx", SUBSTITUTE([message],_splitby,"|")),"pathx",[pathx])
var _generate = GENERATE(_string, GENERATESERIES(1, PATHLENGTH([pathx])))
var _GetVal = SELECTCOLUMNS(_generate, "Msg", PATHITEM([pathx], [Value]))
return
_GetVal
If you have always message.count:::ge::: like string at the end, you can follow these steps in Power Query-
Step 1: Duplicate you message column
Step-2: apply split on new duplicated column using string message.count:::ge::: and you will have a new column with last Numeric value from your original text.
Step-3: you can now apply filter on the new column.
Sample Output-
I'm creating a windows forms application for university. My data is stored in multible c arrays of abstract data types. Each array is displayed in it's own datagridview. This all works no problem.
Since the data is connected like in a database I added a new column to my parent table and set the ColumnType to DataGridViewComboBoxColumn. Now I need to fill this combobox with the data of a different array / datagridview.
I've already tried to add the options manually from my array as discribed in this question: Filling DataGridView ComboBox programatically in unbound mode?. Since I need to use C/C++ and this example uses vb the used functions are not availible. I can select my column dataGridView1->Columns[0] but the ->Items does not exist.
Is it possible to create a datasource from my arrays to link them directly? Or have I overlooked a way to add them manually from my array?
You don't provide any code, neither you describe well where did you ran into a problem. Assuming you're after unbound list to be filled into the DataGridViewComboBoxColumn, here is a simple example.
C#:
DataTable dt;
dt.Columns.Add("ID", typeof(Int32));
dt.Columns.Add("Category", typeof(string));
dt.Rows.Add({1, "Fruits"});
dt.Rows.Add({2, "Vegetables"});
dt.Rows.Add({3, "Trees"});
DataGridViewComboBoxColumn dgCol = this.DataGridView1.columns("Category");
dgCol.ValueMember = "ID";
dgCol.DisplayMember = "Category";
dgCol.DataSource = dt;
In this example, we create a DataTable, fill it with desired values and use it as a DataSource of the DataGridViewComboBoxColumn. Obviously, your values provided to this column in the DataGridView DataSource must match IDs in the list in new DataTable "dt".
You can convert an array or other data into DataTable or even use them directly as DataSource. It depends on what data you have. The principle will be very similar, though.
VB.NET:
Dim dt As DataTable
dt.Columns.Add("ID", GetType(Int32))
dt.Columns.Add("Category", GetType(String))
dt.Rows.Add({1, "Fruits"})
dt.Rows.Add({2, "Vegetables"})
dt.Rows.Add({3, "Trees"})
Dim dgCol As DataGridViewComboBoxColumn = Me.DataGridView1.columns("Category")
dgCol.ValueMember = "ID"
dgCol.DisplayMember = "Category"
dgCol.DataSource = dt
I have a Google sheet which generates an error in the following expression:
=query(Capacity!A5:FE135,"SELECT C,A WHERE "&SUBSTITUTE(ADDRESS(1,match(D2,Capacity!A1:FE1,0)+2,4),"1","")&" = '"&C2&"' AND "&SUBSTITUTE(ADDRESS(1,match(D2,Capacity!A1:FE1,0),4),"1","")&" = 1 ORDER BY C")
for a single, specific input value (a date) at D2.
Essentially, the purpose of the code is to find the column location of the date at D2 in a second sheet (Capacity) and put the values of that column in that sheet into column C in the current sheet, while also selecting only rows that match on a second column. When the date is set to a specific value, however, the expression will not evaluate.
On breaking this massive expression down into its component parts, it turns out the problem is caused by this expression:
=SUBSTITUTE(ADDRESS(1,match(D2,Capacity!A1:FE1,0)+2,4),"1","")
which, for the offending date, is returning column BY.
This means the expression being evaluated in Google Visualization API query language is:
SELECT C,A WHERE BY = '' AND BW = 1 ORDER BY C
but the query language sees BY as a reserved word, not a column, and barfs.
How can I escape the column name somehow to make it clear that it is to be considered a column name?
The way is to surround the offending portion with back-quotes (as I used to make text monospaced here):
=query(Capacity!A5:FE135,"SELECT C,A WHERE `"&SUBSTITUTE(ADDRESS(1,match(D2,Capacity!A1:FE1,0)+2,4),"1","")&"` = '"&C2&"' AND `"&SUBSTITUTE(ADDRESS(1,match(D2,Capacity!A1:FE1,0),4),"1","")&"` = 1 ORDER BY C")
so the query will look like
SELECT C,A WHERE `BY` = '' AND `BW` = 1 ORDER BY C
I assume this will help when the sheet grows so big that we're on column IF as well.
for the following method
Uri uri = ContentUris.withAppendedId((MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
i have read many examples but none of the examples tell me what to do with "id" part of the perameter, i don't want to assign which row because that will change depending of what row the specific image is stored in. so i can't hard code "id". how to deal with this? and can i leave the id as null?
edit
i just found this a few minutes ago from a website, http://www.grokkingandroid.com/android-tutorial-using-content-providers/
values.clear();
values.put(Words.WORD, "Zaphod");
Uri uri = ContentUris.withAppendedId(Words.CONTENT_URI, id);
long noUpdated = resolver.update(uri, values, null, null)
here is the quote from the author, "Since I changed only one record, a URI with an appended ID is sufficient. But if you want to update multiple values, you should use the normal URI and a selection clause."
so he says to use a "normal URI and selection clause" so how do i do that?
this is my selection statement:
String selection = MediaStore.Images.Media.DATA + "='" + filename +"'";
where "filename" is a string variable that varies depending on the image selected, for example, in this case /mnt/sdcard/pic09.png
I'm not sure if I understood your question, but regarding the part when you ask how do you do the normal URI and selection clause, the "trick" is that using content providers you dont put the whole selection in one argument as:
String selection = MediaStore.Images.Media.DATA + "='" + filename +"'";
but instead, you introduce the selection type, selection arguments through different input variables. So for example, the
update where MediaStore.Images.Media.DATA equals filename
becomes:
update (uri, contentValues, String selection, String[] selectionArgs)
where uri points to the table (not the row)
content values point to a ContentValues object with your new values
selection must contain the fields to be compared + comparrisson type + question mark, as
MediaStore.Images.Media.DATA + " = ?";
And selection arguments is an array with all the strings replacing question marks on your selection string, so in your case just
{filename}