我正在将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; }然后,我有一个方法,一次将一个列表输入一个单元格的单元格区域。 我希望能够自动设置这些单元格的列大小。 这是什么样的
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; } }谷歌搜索后,我找到了功能:
在http://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=31292上的columns.OptimalWidth = True
但我不确定如何使用它。 任何人都可以进一步解释这一点或想到另一种让细胞自动调整的方法吗?
I'm entering data from a CSV file into a OpenOffice spreadsheet.
This code gets the a new sheet in a spreadsheet:
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; }I then have method that enters a list into a cell range one cell at a time. I want to be able to automatically set the column size for these cells. which is something like
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; } }After googling i have found the function:
columns.OptimalWidth = True on http://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=31292
but im unsure on how to use this. Could anyone explain this further or think of another way to have the cell autofit?
最满意答案
我理解代码中的注释是西班牙语,但我的代码是英文的。 我通过谷歌翻译运行评论,所以现在他们用英语。 我从这里复制了它:
//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)); }这是做什么的:首先它获取范围名称,然后获取第一列。 但是,真正的代码是使用XpropertySet,这在这里解释得非常好。
I understand the comments in the code are in Spanish I think, but the code is in English. I ran the comments through Google translate so now they are in English. I copied it from here:
//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)); }What this does it this: First it gets the range name and then gets the first column. The real code, though, is XpropertySet being used, which is explained REALLY well here.
更多推荐
发布评论