-
Notifications
You must be signed in to change notification settings - Fork 33
/
JXLSWorkBook.mm
175 lines (138 loc) · 3.47 KB
/
JXLSWorkBook.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//
// JXLSWorkBook.m
// JXLS
//
// Created by David Hoerl on 10/6/08.
// Copyright (c) 2008-2013 David Hoerl. Some rights reserved: <http://opensource.org/licenses/BSD-3-Clause>
// Copyright (c) 2013 Jan Weiß. Some rights reserved: <http://opensource.org/licenses/BSD-3-Clause>
//
#include <stdint.h>
#include <string>
#include "xlslib.h"
#if 0
#include "globalrec.h"
#include "workbook.h"
#include "sheetrec.h"
#include "font.h"
#include "format.h"
#include "extformat.h"
#endif
using namespace xlslib_core;
using namespace xlslib_strings;
#import "JXLSWorkBook.h"
#import "JXLSWorkSheet.h"
#import "JXLSFont.h"
#import "JXLSFormat.h"
#import "JXLSExtendedFormat.h"
@implementation JXLSWorkBook
{
xlslib_core::workbook *_workBook;
NSMutableArray *_workSheets;
}
- (instancetype)init
{
self = [super init];
// only time we actually allocate a C++ object
_workBook = new workbook;
_workSheets = [NSMutableArray arrayWithCapacity:3];
return self;
}
- (void)dealloc
{
delete _workBook;
}
- (JXLSWorkSheet *)workSheetWithName:(NSString *)name
{
JXLSWorkSheet *aWorkSheet;
worksheet *ws;
ustring uniStr;
@autoreleasepool {
unichar *uniName = (unichar *)[name cStringUsingEncoding:NSUnicodeStringEncoding];
uniStr.assign(uniName);
}
ws = _workBook->sheet(uniStr);
aWorkSheet = [[JXLSWorkSheet alloc] initWithWorkSheet:ws];
[_workSheets addObject:aWorkSheet];
return aWorkSheet;
}
- (JXLSWorkSheet *)workSheetForOffset:(uint16_t)offset
{
if([_workSheets count] < offset) {
return nil;
}
return [_workSheets objectAtIndex:offset];
}
- (JXLSFont *)fontWithName:(NSString *)name
{
JXLSFont *aFont;
font_t *ft;
ft = _workBook->font([name cStringUsingEncoding:NSASCIIStringEncoding]);
aFont = [[JXLSFont alloc] initWithFont:ft];
return aFont;
}
- (JXLSFormat *)formatWithString:(NSString *)name
{
JXLSFormat *format;
format_t *ft;
ustring uniStr;
@autoreleasepool {
unichar *uniName = (unichar *)[name cStringUsingEncoding:NSUnicodeStringEncoding];
uniStr.assign(uniName);
}
ft = _workBook->format(uniStr);
format = [(JXLSFormat *)[JXLSFormat alloc] initWithFormat:ft];
return format;
}
- (JXLSExtendedFormat *)extendedFormat
{
return [self extendedFormatForFont:nil];
}
- (JXLSExtendedFormat *)extendedFormatForFont:(JXLSFont *)name
{
JXLSExtendedFormat *xFormat;
xf_t *ft;
if(name) {
ft = _workBook->xformat((font_t *)[name font]);
} else {
ft = _workBook->xformat();
}
xFormat = [[JXLSExtendedFormat alloc] initWithExtendedFormat:ft];
return xFormat;
}
- (BOOL)setValue:(NSString *)content forProperty:(property_t)prop
{
bool ret;
ret = _workBook->property(prop, [content cStringUsingEncoding:NSUTF8StringEncoding]);
return ret ? YES : NO;
}
- (void)setWindowPositionX:(uint16_t)horz Y:(uint16_t)vert
{
_workBook->windPosition((unsigned16_t)horz, (unsigned16_t)vert);
}
- (void)setWindowSizeX:(uint16_t)horz Y:(uint16_t)vert
{
_workBook->windSize((unsigned16_t)horz, (unsigned16_t)vert);
}
- (void)firstTab:(uint16_t)tab
{
_workBook->firstTab((unsigned16_t)tab);
}
- (void)tabBarWidth:(uint16_t)width
{
_workBook->tabBarWidth((unsigned16_t)width);
}
- (int)writeToFile:(NSString *)name
{
string filename;
filename = [name fileSystemRepresentation];
return _workBook->Dump(filename);
}
#define WORKBOOK(a) ((xlslib_core::workbook *)(a))
- (BOOL)setColorWithRed:(uint8_t)red
green:(uint8_t)green
blue:(uint8_t)blue
index:(uint8_t)idx
{
return WORKBOOK(_workBook)->setColor(red, green, blue, idx);
}
@end