1

I'm writing a Powershell script to enforce "General Formatting" of Column AI. This is what I have and it didn't appear to execute.

$worksheet.columns.items('AI').GeneralFormat = $true

What is the right Powershell code for such a task?

General Formatting:

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
jreyez
  • 171
  • 3
  • 4
  • 15

2 Answers2

4

The clue is in your screenshot; the tooltip specifies this is the "Number Format" setting.

$worksheet.Columns("AI").NumberFormat = "General"

Check out the MSDN page on NumberFormat. Unfortunately it doesn't list the allowed values; this StackOverflow q/a appears to cover that.

G42
  • 9,791
  • 2
  • 19
  • 34
3

This works

$Excel01 = New-Object -ComObject Excel.Application
$Excel01.Visible = $True
$Workbook01 = $Excel01.Workbooks.Add()
$Worksheet01 = $Workbook01.Sheets.Item(1)
$Worksheet01.Activate()
$Excel01.Columns.item('d').NumberFormat = "0"
Leo Louis
  • 31
  • 1