Aspose.Word - How to make use of full table cell width? - aspose

I have a table in a word document and would like to make use of FULL cell width to insert data.
Default behaviour is that it is leaving spaces (padding) as below.
How can i make use of the total width of a column without leaving any space?

You can use Aspose.Words to adjust amount of space (in points) to the left, right, below or above the contents of cells. Please try using the following code:
Document doc = new Document(MyDir + #"input.docx");
Table tab = doc.FirstSection.Body.Tables[0];
tab.BottomPadding = 0;
tab.LeftPadding = 0;
tab.RightPadding = 0;
tab.TopPadding = 0;
doc.Save(MyDir + #"17.7.docx");
Hope, this helps.
I work with Aspose as Developer Evangelist.

Related

Google Sheets: How can I extract partial text from a string based on a column of different options?

Goal: I have a bunch of keywords I'd like to categorise automatically based on topic parameters I set. Categories that match must be in the same column so the keyword data can be filtered.
e.g. If I have "Puppies" as a first topic, it shouldn't appear as a secondary or third topic otherwise the data cannot be filtered as needed.
Example Data: https://docs.google.com/spreadsheets/d/1TWYepApOtWDlwoTP8zkaflD7AoxD_LZ4PxssSpFlrWQ/edit?usp=sharing
Video: https://drive.google.com/file/d/11T5hhyestKRY4GpuwC7RF6tx-xQudNok/view?usp=sharing
Parameters Tab: I will add words in columns D-F that change based on the keyword data set and there will often be hundreds, if not thousands, of options for larger data sets.
Categories Tab: I'd like to have a formula or script that goes down the columns D-F in Parameters and fills in a corresponding value (in Categories! columns D-F respectively) based on partial match with column B or C (makes no difference to me if there's a delimiter like a space or not. Final data sheet should only have one of these columns though).
Things I've Tried:
I've tried a bunch of things. Nested IF formula with regexmatch works but seems clunky.
e.g. this formula in Categories! column D
=IF(REGEXMATCH($B2,LOWER(Parameters!$D$3)),Parameters!$D$3,IF(REGEXMATCH($B2,LOWER(Parameters!$D$4)),Parameters!$D$4,""))
I nested more statements changing out to the next cell in Parameters!D column (as in , manually adding $D$5, $D$6 etc) but this seems inefficient for a list thousands of words long. e.g. third topic will get very long once all dog breed types are added.
Any tips?
Functionality I haven't worked out:
if a string in Categories B or C contains more than one topic in the parameters I set out, is there a way I can have the first 2 to show instead of just the first one?
e.g. Cell A14 in Categories, how can I get a formula/automation to add both "Akita" & "German Shepherd" into the third topic? Concatenation with a CHAR(10) to add to new line is ideal format here. There will be other keywords that won't have both in there in which case these values will just show up individually.
Since this data set has a bunch of mixed breeds and all breeds are added as a third topic, it would be great to differentiate interest in mixes vs pure breeds without confusion.
Any ideas will be greatly appreciated! Also, I'm open to variations in layout and functionality of the spreadsheet in case you have a more creative solution. I just care about efficiently automating a tedious task!!
Try using custom function:
To create custom function:
1.Create or open a spreadsheet in Google Sheets.
2.Select the menu item Tools > Script editor.
3.Delete any code in the script editor and copy and paste the code below into the script editor.
4.At the top, click Save save.
To use custom function:
1.Click the cell where you want to use the function.
2.Type an equals sign (=) followed by the function name and any input value — for example, =DOUBLE(A1) — and press Enter.
3.The cell will momentarily display Loading..., then return the result.
Code:
function matchTopic(p, str) {
var params = p.flat(); //Convert 2d array into 1d
var buildRegex = params.map(i => '(' + i + ')').join('|'); //convert array into series of capturing groups. Example (Dog)|(Puppies)
var regex = new RegExp(buildRegex,"gi");
var results = str.match(regex);
if(results){
// The for loops below will convert the first character of each word to Uppercase
for(var i = 0 ; i < results.length ; i++){
var words = results[i].split(" ");
for (let j = 0; j < words.length; j++) {
words[j] = words[j][0].toUpperCase() + words[j].substr(1);
}
results[i] = words.join(" ");
}
return results.join(","); //return with comma separator
}else{
return ""; //return blank if result is null
}
}
Example Usage:
Parameters:
First Topic:
Second Topic:
Third Topic:
Reference:
Custom Functions
I've added a new sheet ("Erik Help") with separate formulas (highlighted in green currently) for each of your keyword columns. They are each essentially the same except for specific column references, so I'll include only the "First Topic" formula here:
=ArrayFormula({"First Topic";IF(A2:A="",,IFERROR(REGEXEXTRACT(LOWER(B2:B&C2:C),JOIN("|",LOWER(FILTER(Parameters!D3:D,Parameters!D3:D<>""))))) & IFERROR(CHAR(10)&REGEXEXTRACT(REGEXREPLACE(LOWER(B2:B&C2:C),IFERROR(REGEXEXTRACT(LOWER(B2:B&C2:C),JOIN("|",LOWER(FILTER(Parameters!D3:D,Parameters!D3:D<>""))))),""),JOIN("|",LOWER(FILTER(Parameters!D3:D,Parameters!D3:D<>""))))))})
This formula first creates the header (which can be changed within the formula itself as you like).
The opening IF condition leaves any row in the results column blank if the corresponding cell in Column A of that row is also blank.
JOIN is used to form a concatenated string of all keywords separated by the pipe symbol, which REGEXEXTRACT interprets as OR.
IFERROR(REGEXEXTRACT(LOWER(B2:B&C2:C),JOIN("|",LOWER(FILTER(Parameters!D3:D,Parameters!D3:D<>""))))) will attempt to extract any of the keywords from each concatenated string in Columns B and C. If none is found, IFERROR will return null.
Then a second-round attempt is made:
& IFERROR(CHAR(10)&REGEXEXTRACT(REGEXREPLACE(LOWER(B2:B&C2:C),IFERROR(REGEXEXTRACT(LOWER(B2:B&C2:C),JOIN("|",LOWER(FILTER(Parameters!D3:D,Parameters!D3:D<>""))))),""),JOIN("|",LOWER(FILTER(Parameters!D3:D,Parameters!D3:D<>"")))))
Only this time, REGEXREPLACE is used to replace the results of the first round with null, thus eliminating them from being found in round two. This will cause any second listing from the JOIN clause to be found, if one exists. Otherwise, IFERROR again returns null for round two.
CHAR(10) is the new-line character.
I've written each of the three formulas to return up to two results for each keyword column. If that is not your intention for "First Topic" and "Second Topic" (i.e., if you only wanted a maximum of one result for each of those columns), just select and delete the entire round-two portion of the formula shown above from the formula in each of those columns.

Google Sheet Conditional Formatting highlight 2 columns if one column contain certain text of 5 columns

In Google Sheet, I want to highlight only 2 columns out of 5 columns.
5 columns here but I want to highlight only 'Name' and 'Weight' columns if a cell contain the word 'Smith'
The outcome should be like this.
I want to input more name and if the name contain the word 'Smith', I want it to be automatically highlighted for name and weight columns.
I tried to use conditional formatting in Google sheet, and I could highlight only the name column.
This is what I tried.
Outcome was this.
You are not far, try the following formula in the conditional formatting:
=IF(REGEXMATCH($C3, "Smith"), 1, 0)
The formula given by #nabais works.
In conditional formatting though one does not need to use the starting IF function.
"Format cells if" is how conditional formatting rules are formed by default as noted in the official help page.
Create a rule.
Single color: Under "Format cells if," choose the condition that you want to trigger the rule. Under "Formatting style, choose what the
cell will look like when conditions are met.
Color scale: Under "Preview," select the color scale. Then, choose a minimum and maximum value, and an optional midpoint value. To choose
the value category, click the Down arrow Down Arrow.
So the following formula is all that is needed:
(Please adjust ranges to your needs)
=REGEXMATCH($G2, "Smith")
You can try the following code:
function highlight() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var data = ss.getRange('A1:E').getValues();
for (i = 1; i < data.length; i++) {
var tf = ss.getRange("B" + i).createTextFinder('smith');
tf.matchEntireCell(false);
tf.matchCase(false);
var result = tf.findNext();
if (result !== null) {
var range = result.getRow();
ss.getRange('B' + range).setBackground('Yellow');
ss.getRange('D' + range).setBackground('Yellow');
}
};
};

Array Formula to Automatically Calculate

I want an array formula to use with Google Forms data to automatically calculate running metrics on my data.
In this case, in column BF I want it to auto-calculate whenever new responses come in.
I'm trying to use this formula below but isn't working for all column, just for the first line.
=ArrayFormula(If(isblank($BF$3:$BF);"";(INDEX($C$1:$BD$1;0;MATCH(MAX($C3:$BD3);$C3:$BD3;0)))))
What I'm doing wrong?
My Google Sheet:
https://docs.google.com/spreadsheets/d/1iD75djqdY8qtClEHpKUEvAS55bP0ARv9AnDUz9mFBuc/edit?usp=sharing
delete range BE:BF
paste this in BE1:
={"MAX"; ""; ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(C3:BD);
"select "&TEXTJOIN(","; 1; IF(A3:A<>"";
"max(Col"&ROW(A3:A)-ROW(A3)+1&")"; ))&""));
"select Col2"; 0))}
paste this in BF1:
={"TIPO"; ""; ARRAYFORMULA(IF(A3:A="";;TRIM(TRANSPOSE(QUERY(TRANSPOSE(
IF(C3:BD=QUERY(TRANSPOSE(QUERY(TRANSPOSE(C3:BD);
"select "&TEXTJOIN(","; 1; IF(A3:A<>"";
"max(Col"&ROW(A3:A)-ROW(A3)+1&")"; ))&""));
"select Col2"; 0); C1:1; ));;99^99)))))}

Removing a row containing a specific text in Google Sheets

I have a data set of around 3000 columns, but some of the columns have several cells that contain cells "na". These rows have no importance since they don't have data that I will need, is there a command in google sheets that can either highlight the entire row that contains that text or delete the entire row containing that text?
Any help would be appreciated.
https://docs.google.com/spreadsheets/d/1u8OUfQOzgAulf1a8bzQ8SB5sb5Uvb1I4amF5sdGEBlc/edit?usp=sharing
My document ^.
you can use this formula to color all na rows:
=ARRAYFORMULA(REGEXMATCH(TRANSPOSE(QUERY(TRANSPOSE($A1:$Z),,999^99)), " na "))
This answer based on what I understand, sorry if I'm wrong. You can use conditional formatting to highlight all NA text
This is what rules I used
Here are another answers that may help you
Delete a row in Google Spreadsheets if value of cell in said row is 0 or blank
Google Sheets: delete rows containing specified data
Deleting Cells in Google Sheets without removing a whole row
Sorry for bad English.
I'm not sure if my understing is well but see below what you can do.
This is a google script function which color the whole column where "na" is in
function myFunction() {
//get the spreadsheet where the function is running
var ss = SpreadsheetApp.getActive()
//Replace "the name of your sheet" by your sheet name" be careful its case sensitive.
var sheet = ss.getSheetByName("The name of your sheet")
//Get all your data as an array (If your sheet has no header, change 2 by 1 and (sheet.getLastRow()-1) by sheet.getLastRow())
var values = sheet.getRange(2,1,(sheet.getLastRow()-1), sheet.getLastColumn()).getValues();
//For each column
for (var i = 0; i< sheet.getLastColumn(); i++){
//using function map is helping to select one column by one column
var mapValues = values.map(function(r){return r[i]});
//Searching your keyword in the column, in your case it's "na"
var position = mapValues.indexOf("Put the string that you are looking for, in your case 'na'");
//if at least there is one "na" inside the column
if( position >-1){
//then this color have to get red color as a background
var wholeColumn = sheet.getRange(2,(i+1),(sheet.getLastRow()-1));
wholeColumn.setBackground("red");
}
}
}``
Let me know if it works

Add empty option to List Validator

I'm trying to add the option to my users that, on a List Validator, to allow select any of the options or a blank option. Spreadjs has the IgnoreBlanks setting, which I use, so when the user uses the delete key or the backspace and deletes the cell it validates correctly.
However, I would love to use the same functionality as in Excel, which allows blank options in the list validator, in part of the list.
I've tried to target the <select> element that holds the list and programmatically add the empty element, however, it crashes after the user selects the empty option.
I've also tried to add different escaped characters to the list. If I select a character that represents an empty string or a tab, it won't add a new option to the list. If I use any strange character, or even the null character \0 you get a new option to select, but the content is that typical rectangle you see when your font doesn't have the character you're trying to display.
I've also tested using a regular ListValidator like in the example pages, not our custom functionality and doesn't work either.
https://www.grapecity.com/demos/spread/JS/TutorialSample/#/demos/basicDataValidator
I have also tried creating a FormulaListValidator, and if my range has empty cells I could then get an empty option on my list, however, because the range may have duplicates, I get duplicated options.
After researching a little bit I found a workaround in a different language which I adapted to Typescript (Angular 6)
export const getListValidatorFromArray = (spread: GC.Spread.Sheets.Workbook, data: any[]) => {
// saving validation list values in a hidden sheet
spread.addSheet(spread.getSheetCount());
const sheet = spread.getSheet(spread.getSheetCount() - 1);
sheet.visible(false);
for (let i = 0; i < data.length; i++) {
sheet.setValue(i, 0, data[i]);
}
// create validator based on the values
const dv = GC.Spread.Sheets.DataValidation.createFormulaListValidator(
'=' + sheet.name() + '!$A$1:' + sheet.name() + '!$A$' + data.length
);
return dv;
};
Note: This creates an extra sheet for each validator you create. Makes sure you reuse them as much as possible (i.e. assigning it to a variable when it's created, and reusing the variable for other columns/rows that use the same one).