Mat*_*don 3 c# openoffice-calc
我正在将CSV文件中的数据输入OpenOffice电子表格.
此代码在电子表格中获取新工作表:
Public Spreadsheet getSpreadsheet(int sheetIndex, XComponent xComp)
{
XSpreadsheet xSheets = ((XSpreadsheetDocument)xComp).getSheets();
XIndexAccess xSheetIA = (XIndexAccess)xSheets;
XSpreadsheet XSheet = (XSpreadsheet)xSheetsA.getByIndex(sheetIndex).Value;
return XSheet;
}
Run Code Online (Sandbox Code Playgroud)
然后,我有一个方法,一次将一个列表输入一个单元格的单元格区域.我希望能够自动设置这些单元格的列大小.这是什么样的
string final DataCell;
Xspreadsheet newSheet = getSpreadsheet(sheetIndex, xComp);
int numberOfRecords = ( int numberOfColumns * int numberOfRows);
for(cellNumber = 0; cellNumber < numberOfrecords; cellNumber++)
{
XCell tableData = newSheet.getCellbyPosition(columnValue, rowValue);
((XText)tableData).setString(finalDataCell);
column Value++;
if(columnValue > = numberOfColumns)
{
rowVal++ column = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
谷歌搜索后,我找到了功能:
columns.OptimalWidth = True在http://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=31292
但我不确定如何使用它.任何人都可以进一步解释这一点,或者想到让细胞自动调整的另一种方法吗?
我理解代码中的注释是西班牙语,但我的代码是英文的.我通过谷歌翻译运行评论,所以现在他们用英语.我从这里复制了它:
//Auto Enlarge col width
private void largeurAuto(string NomCol)
{
XCellRange Range = null;
Range = Sheet.getCellRangeByName(NomCol + "1"); //Recover the range, a cell is
XColumnRowRange RCol = (XColumnRowRange)Range; //Creates a collar ranks
XTableColumns LCol = RCol.getColumns(); // Retrieves the list of passes
uno.Any Col = LCol.getByIndex(0); //Extract the first Col
XPropertySet xPropSet = (XPropertySet)Col.Value;
xPropSet.setPropertyValue("OptimalWidth", new one.Any((bool)true));
}
Run Code Online (Sandbox Code Playgroud)
这是做什么的:首先它获取范围名称,然后获取第一列.不过,真正的代码是使用了XpropertySet,这在这里解释得非常好.
| 归档时间: |
|
| 查看次数: |
1848 次 |
| 最近记录: |