3

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;
}

次に、一度に 1 セルずつセル範囲にリストを入力するメソッドがあります。これらのセルの列サイズを自動的に設定できるようにしたいと考えています。これは次のようなものです

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; 
  } 
}

グーグルの後、私は関数を見つけました:

columns.OptimalWidth = Truehttp://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=31292

しかし、これを使用する方法がわかりません。誰かがこれをさらに説明したり、セルを自動調整する別の方法を考えたりできますか?

4

2 に答える 2

5

コードのコメントはスペイン語だと思いますが、コードは英語です。コメントを Google 翻訳で調べたので、現在は英語になっています。ここからコピーしました:

//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 が使用されており、ここで詳しく説明されています。

于 2013-01-13T20:45:20.027 に答える
0
   public void optimalWidth(XSpreadsheet newSheet)
        {
        // gets the used range of the sheet
            XSheetCellCursor XCursor = newSheet.createCursor();
            XUsedAreaCursor xUsedCursor = (XUsedAreaCursor)XCursor;
            xUsedCursor.gotoStartOfUsedArea(true);
            xUsedCursor.gotoEndOfUsedArea(true); 

            XCellRangeAddressable nomCol = (XCellRangeAddressable)xUsedCursor;


            XColumnRowRange RCol = (XColumnRowRange)nomCol;
            XTableColumns LCol = RCol.getColumns();
       // loops round all of the columns
            for (int i = 0; i < nomCol.getRangeAddress().EndColumn;i++) 
            {
            XPropertySet xPropSet = (XPropertySet)LCol.getByIndex(i).Value; 
            xPropSet.setPropertyValue("OptimalWidth", new uno.Any(true));
            }
        }
于 2013-01-14T10:56:19.563 に答える