我正在尝试以编程方式创建 XLS 工作表。我可以在 XLS 文件中创建单个工作表,但是当我尝试创建两个工作表时,出现错误。该文件已创建,但我无法打开该文件。我只能在使用单张创建文件时打开文件。
这是我尝试过的:
RSworkBook * folder = [ [RSworkBook alloc] init];
folder.author = @"andrea cappellotto";
folder.version = 1.2;
RSworkSheet * sheet = [[RSworkSheet alloc] initWithName"prova"];
RSworkSheet * sheet2 = [[RSworkSheet alloc] initWithName"222"];
RSworkSheetRow * row = [[RSworkSheetRow alloc] initWithHeight:20];
[row addCellString"prova"];
[row addCellString"prova2"];
[sheet addWorkSheetRow:row];
[sheet2 addWorkSheetRow:row];
RSworkSheetRow * row2 = [[RSworkSheetRow alloc] initWithHeight:25];
[row2 addCellNumber:100];
[row2 addCellData:[NSDate date] ];
[sheet addWorkSheetRow:row2];
[sheet2 addWorkSheetRow:row];
[folder addWorkSheet:sheet];
[folder addWorkSheet:sheet2];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
[folder writeWithName"prova" toPath:documentsDir];
这里是生成的xml代码:
<?xml version="1.0" encoding="UTF-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns:c="urn:schemas-microsoft-comffice:component:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns="urn:schemas-microsoft-comfficeffice"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:schemas-microsoft-comffice:spreadsheet"
xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml"
xmlns:ss="urn:schemas-microsoft-comffice:spreadsheet"
xmlns:x="urn:schemas-microsoft-comffice:excel">
<DocumentProperties xmlns="urn:schemas-microsoft-comfficeffice"><Author>andrea cappellotto</Author>
<LastAuthor>andrea cappellotto</LastAuthor>
<Created>2015-07-09</Created>
<Version>1.20</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-comffice:office">
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>20000</WindowHeight>
<WindowWidth>20000</WindowWidth>
<WindowTopX>0</WindowTopX>
<WindowTopY>0</WindowTopY>
<rotectStructure>False</ProtectStructure>
<rotectWindows>False</ProtectWindows>
</ExcelWorkbook><Styles><Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center" ss:Horizontal="Center"/>
<Borders/>
<Font ss:FontName=".HelveticaNeueInterface-Regular" ss:Size="14.00" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<rotection/>
</Style>
<Style ss:ID="s60">
<NumberFormat ss:Format="Short Date"/>
</Style>
</Styles>
<Worksheet ss:Name="prova">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1" ssefaultColumnWidth="0.00" ssefaultRowHeight="20.00">
<Column ss:Width="80"/>
<Row ss:AutoFitHeight="0" ss:Height="20.00" >
<Cell>
<Data ss:Type="String">prova</Data>
</Cell>
<Cell>
<Data ss:Type="String">prova2</Data>
</Cell>
</Row>
<Row ss:AutoFitHeight="0" ss:Height="25.00" >
<Cell>
<Data ss:Type="Number">100.00</Data>
</Cell>
<Cell ss:StyleID="s60">
<Data ss:Type="DateTime">2015-07-09</Data>
</Cell>
</Row>
</Table>
<WorksheetOptions/>
</Worksheet>
<Worksheet ss:Name="222">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1" ssefaultColumnWidth="0.00" ssefaultRowHeight="20.00">
<Column ss:Width="80"/>
<Row ss:AutoFitHeight="0" ss:Height="20.00" >
<Cell>
<Data ss:Type="String">prova</Data>
</Cell>
<Cell>
<Data ss:Type="String">prova2</Data>
</Cell>
</Row>
<Row ss:AutoFitHeight="0" ss:Height="20.00" >
<Cell>
<Data ss:Type="String">prova</Data>
</Cell>
<Cell>
<Data ss:Type="String">prova2</Data>
</Cell>
</Row>
</Table>
<WorksheetOptions/>
</Worksheet>
</Workbook>
Best Answer-推荐答案 strong>
我找到了另一个库来在 xls 文件中创建多个工作表。它是 libxl。我可以使用以下行添加尽可能多的工作表:
SheetHandle sheet = xlBookAddSheet(book, [sheetNAme UTF8String], NULL);
关于ios - 如何在 iOS 中使用 RSSheet 创建多个工作表?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/31324192/
|