I have created a a project that reads different files and puts then in different sheets with a spreadsheet. I have used Open office calc spreadsheet therefore used the following code to open a blank file:
public XSpreadsheet getSpreadsheet(int nIndex, XComponent xComp)
{
XSpreadsheets xSheets = ((XSpreadsheetDocument)xComp).getSheets();
XIndexAccess xSheetsIA = (XIndexAccess)xSheets;
XSpreadsheet xSheet =(XSpreadsheet)xSheetsIA.getByIndex(nIndex).Value;
return xSheet;
}
I call a sheet to be used like so:
XSpreadsheet newSheet = getSpreadsheet(sheetIndex, xComp);
where xComp
is:
string filePathway = @"file:///c:/temp/blank.ods";
PropertyValue[] propVals = new PropertyValue[0];
XComponent oCalcuDoc = oDesktop.loadComponentFromURL(filePathway, "_blank", 0, propVals);
However my problem is that file blank.ods needs to be set up with the number of sheets that will be required already inserted into the spreadsheet before the application is run. This is not ideal as the number of sheets needed is not always known. Is there a way of inserting sheets from within my application?
Any help would be appreciated.
On the Home tab, in the Cells group, click Insert, and then click Insert Sheet. Tip: You can also right-click the selected sheet tabs, and then click Insert.
Add(misValue); xlWorkSheet = (Excel. Worksheet)xlWorkBook. Worksheets. get_Item(numberOfLetters); foreach (string letter in letters) { xlWorkSheet.
Press with mouse on "Run" button. An input box appears asking for a cell range. Select a cell range and press with left mouse button on the "OK" button. Worksheets are now added automatically to the workbook and named correspondingly after the values in the cell range.
Answer: There are two methods of adding a new worksheet iasm Excel workbook; Insert worksheet tab at the bor >m and Insert button on cells group under Home tab.
I just took a brief look at the OpenOffice API and found this: http://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/XSpreadsheets.html
.. it states that the interface XSpreadsheets
:
provides methods to access the spreadsheets by name and to insert, copy, remove and rearrange spreadsheets.
It includes methods like:
insertNewByName
, which according to the API documentation:
inserts a new sheet into the collection.
see: http://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/XSpreadsheets.html#insertNewByName
... and so on.
I'm by no means an OpenOffice API expert - I just took a brief view at their API documenation - hope this can point you in the right direction.
Actually, the documentation contains an example of how to add a new sheet in a document:
/** Inserts a new empty spreadsheet with the specified name.
@param xDocument The XSpreadsheetDocument interface of the document.
@param aName The name of the new sheet.
@param nIndex The insertion index.
@return The XSpreadsheet interface of the new sheet.
*/
public com.sun.star.sheet.XSpreadsheet insertSpreadsheet(
com.sun.star.sheet.XSpreadsheetDocument xDocument,
String aName, short nIndex ) {
// Collection of sheets
com.sun.star.sheet.XSpreadsheets xSheets = xDocument.getSheets();
com.sun.star.sheet.XSpreadsheet xSheet = null;
try {
xSheets.insertNewByName(aName, nIndex);
xSheet = xSheets.getByName( aName );
} catch (Exception ex) {
}
return xSheet;
}
The example can be seen at the bottom of this page: http://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Working_With_Spreadsheet_Documents
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With