2012-12-20 2 views
3

CSV 파일의 데이터를 OpenOffice 스프레드 시트에 입력하고 있습니다.최적의 열 너비 OpenOffice Calc

이 코드는 스프레드 시트에서 새 시트를 가져옵니다

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

그때 한 번에 셀 범위 하나 개의 셀에 목록을 입력하는 방법이있다. 이러한 셀의 열 크기를 자동으로 설정할 수 있기를 원합니다.

columns.OptimalWidth = True

http://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=31292에 있지만 사용 방법에 대한 확신 메신저 : 어느 내가 기능을 발견 인터넷 검색 후

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

같은 것입니다. 누구나 이것을 더 설명 할 수 있을까요, 아니면 세포를 자동 설치하는 다른 방법을 생각해 낼 수 있습니까?

답변

5

나는 코드의 주석이 스페인어로되어 있다고 생각한다.하지만 코드는 영어로되어있다. Google 번역을 통해 코멘트를 실행 했으므로 지금은 영어로되어 있습니다. 나는 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)); 
} 

이가이 작업을 수행하는 것 : 첫째는 범위 이름을 가져옵니다 후 첫 번째 열을 가져옵니다. 실제 코드는 XpropertySet을 사용하고 있는데, 실제로 잘 설명되어 있습니다. here.

+0

이 코드의 약간 다른 버전을 사용할 수있게되어서 고맙습니다. 그러나이 코드는 실제로 도움이되었습니다. 나는 다른 버전을 도울 수있는 encase 아래에 내 버전을 넣을거야. 다시 한번 감사드립니다. –

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