我有一个.xlsx文件,我需要纠正多个列才能使用正确的格式。我一直试图通过Powershell使用=Proper(),=Lower()和even =Upper(),但都没有成功。
有没有人碰巧知道怎么做?谢谢
$worksheet = C:\Users\USERNAME\Downloads\Book1.xlsx
Import-Module PSExcel
$worksheet.Columns("Name, 'Primary Worksite', 'Primary Job Title'").ToProper()发布于 2021-09-20 20:59:45
下面是一个使用COM的示例--关键是通过WorksheetFunctions类调用Proper函数,该类提供了对内置到Excel中的所有函数的编程访问。
其他库和模块可能会为您提供包装器……
# setup - create a new workbook with "aaa bbb ccc" in cell A1
$excel = new-object -ComObject Excel.Application;
$excel.Visible = $true;
$workbook = $excel.Workbooks.Add();
$workbook.Sheets(1).Range("A1").Value = "aaa bbb ccc";
# get the text from a range
$range = $workbook.Sheets(1).Range("A1");
$originalText = $range.Text;
# convert it to "Proper Case"
# (see https://docs.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.proper)
$properText = $excel.WorksheetFunction.Proper($originalText);
# set the new text back into the cell
$range.Value = $properText; # Aaa Bbb Ccc
# clean up
$workbook.Close($false);
$excel.Quit();https://stackoverflow.com/questions/69260359
复制相似问题