How to set cellType "General" to "Number" using NPOI - npoi

I have simple cell and formula cell in both of case i want to set cell type number but it takes default general type. Plz help me how can i set cell type general to number type.

We can change cell format in following way:
Dim CellFormat As HSSFCellStyle = HSSFWorkbook.CreateCellStyle()
CellFormat.DataFormat = &H29
Here &H29 is direct value of specific format if we want to get format then can follow:
Dim CellFormat As HSSFCellStyle = HSSFWorkbook.CreateCellStyle()
CellFormat.DataFormat = HSSFDataFormat.GetBuiltinFormat("#,##0")

Related

How to display in a form/tree view a computed field with store = False ?Odoo 11

In Odoo 11, How to display in a form/tree view a computed field with store = False ?
For example :
The field Marge is a computed field with store=False
margin_pct = fields.Char(string = 'Marge', compute =
_getmarginpct)
When the view is in modify mode the value of the field marge is displayed and modified as well
modify image
But when the view is in save mode or when we come back on the view the value of the field marge is not displayed
save image
Thanks for your answers.
You must be modifying the value of margin_pct field in an onchange function. Since this field is read only the values modified by on change functions will not be saved. So use depends instead of onchange and it should work.

Macro in word to add text box with file path

I'm totally new to this. I want to create a macro that add to my document the file path (at the time when the macro runs) into a text box that goes at the end of the document. I use Word 2016 for Mac.
I've found code on other threads that helped me to understand how to create the text box and work on its position in the document but I'm not able to add the file path code.
This is what I came up with so far:
Sub percorsofile2()
Dim Box As Shape
Set Box = ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=50, Top:=50, Width:=100, Height:=15)
Box.TextFrame.TextRange: Selection.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, Text:="FILENAME \p "
You're very close! Just one little change...
The Selection is not in the TextBox, which is why the field code is not getting inserted in the right place. While you could first select the TextBox range, it's usually better to work directly with a Range object, rather than a selection.
My sample code declares a Range object, then sets it to the Box.TextFrame.TextRange. The field code can then be inserted at this position.
Sub percorsofile2()
Dim Box As Shape
Dim rng As Word.Range
Set Box = ActiveDocument.shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=50, Top:=50, width:=100, height:=15)
Set rng = Box.TextFrame.TextRange
rng.Fields.Add Range:=rng, Type:=wdFieldEmpty, Text:="FILENAME \p "
End Sub

How do I programmatically put a text value into a NSTextField in OSX?

I am able to type a value into the text field and add the value to an array I created. Therefore I know the delegate is set correctly.
When I try to set the text field with the value from the array it will not set and the field is empty.
I am setting the text field like this:
setStringValue:inputDecsription = [descriptionArrayobjectAtIndex:selected];
NSLog(#"Description %#", inputDecsription);
Description Florida Power
The text field remains empty. What am I doing wrong?

How to make a range in Numbers (iWork) using JXA

I'm using JXA for automating a process using Numbers app. What I need is to select a range of cells to apply width, but JXA doesn't allow me to get them.
According to apple documentation I only need to use make or push the created object inside of array, but any ones work. This is my code and the Automator error:
Option 1:
var Numbers = Application('Numbers');
Numbers.Range({name: 'A2:A20'}).make();
// -> Error: Can't make or move that element into that container
Option 2:
var Numbers = Application('Numbers');
var myRange = Numbers.Range({name: 'A2:A20'});
Numbers.documents[0].sheets[0].tables[0].ranges.push(myRange);
// -> Error: Can't create object.
Option 3:
var Numbers = Application('Numbers');
var myRange = Numbers.Range({name: 'A2:A20'});
Numbers.documents[0].sheets[0].tables[0].selectionRange = myRange;
// -> Automator close with an unexpected error
According to AppleScript documentation (syntax is very different to Javascript) I can do it assigning text that represent the range:
set selection range of table 1 to range "H5:K8"
But if I do something like that with Javascript, it does not work:
Option 4:
var Numbers = Application('Numbers');
Numbers.documents[0].sheets[0].tables[0].selectionRange = 'A2:A20'
// -> Error: Can't convert types.
I have searched for it, but I have not found anything that help me (good references are about AppleScript and the few references that contain something about JXA are about Mail).
Thank you for your help (any link with documentation or any ides to try will be appreciate).
This AppleScript:
tell application "Numbers"
tell table 1 of sheet 1 of document 1
set selection range to range "A2:A20"
end tell
end tell
is actually setting the table's selection range to the table's range named "A2:A20".
Here is the equivalent JavaScript:
var Numbers = Application("Numbers")
var table = Numbers.documents[0].sheets[0].tables[0]
table.selectionRange = table.ranges["A2:A20"]

Using Javascript for Automation to copy cells in Numbers

I want to use JXA to automate some updating of Numbers spreadsheets. For example, copying a range of cells from one spreadsheet to another one with a different structure.
At this point, I'm just testing a simple program to set or read the value of a cell and I can't get this to work.
When I try to set a value I get "Error -1700: Can't convert types." and when I try to read a value I get back a [object ObjectSpecifier] rather than a text or number value.
Here's an example of the code:
Numbers = Application('Numbers')
Numbers.activate()
delay(1)
doc = Numbers.open(Path('/Users/username/Desktop/Test.numbers'))
currentSheet = doc.Sheets[0]
currentTable = currentSheet.Tables[0]
console.log(currentTable['name'])
console.log(currentTable.cell[1][1])
currentTable.cell[1][1].set(77)
When I run this, I get and output of [object ObjectSpecifier] for the two console.logs and then an error -1700: Can't convert types when it tries to set a cell.
I've tried several other variations of accessing or setting properties but can't get it to work.
Thanks in advance,
Dave
Here is a script that sets and gets a cell's value and then sets a different cell's value in the same table:
// Open Numbers document (no activate or delay is needed)
var Numbers = Application("Numbers")
var path = Path("/path/to/spreadsheet.numbers")
var doc = Numbers.open(path)
// Access the first table of the first sheet of the document
// Note:
// .sheets and .tables (lowercase plural) are used when accessing elements
// .Sheet and .Table (capitalized singular) are used when creating new elements
var sheet = doc.sheets[0]
var table = sheet.tables[0]
// Access the cell named "A1"
var cell = table.cells["A1"]
// Set the cell's value
cell.value = 20
// Get the cell's value
var cellValue = cell.value()
// Set that value in a different cell
table.cells["B2"].value = cellValue
Check out the Numbers scripting dictionary (with JavaScript selected as the language) to see classes and their properties and elements. The elements section will show you the names of elements (e.g. the Document class contains sheets, the Sheet class contains tables, and so on). To open the scripting dictionary, in Script Editor's menu bar, choose Window > Library, and then select Numbers in the library window.
In regards to the logging you were seeing - I recommend using a function similar to this:
function prettyLog(object) {
console.log(Automation.getDisplayString(object))
}
Automation.getDisplayString gives you a "pretty print" version of any object you pass to it. You can then use that for better diagnostic logging.

Resources