├── ExcelDemo ├── ExcelDemo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── molangwu.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── molangwu.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── ExcelDemo.xcscheme │ │ └── xcschememanagement.plist ├── ExcelDemo │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── ExcelDemoDHlibxls-Prefix.pch │ ├── ExcelDemo_Briding_Header.h │ ├── ExcelParser │ │ ├── CSV │ │ │ ├── CSVParser.h │ │ │ └── CSVParser.m │ │ ├── LAWExcelTool.h │ │ ├── LAWExcelTool.m │ │ ├── XLS │ │ │ └── DHxlsReader │ │ │ │ ├── DHxlsReaderIOS │ │ │ │ ├── DHcell-Private.h │ │ │ │ ├── DHcell.h │ │ │ │ ├── DHcell.m │ │ │ │ ├── DHxlsReaderIOS-Prefix.pch │ │ │ │ ├── DHxlsReaderIOS.h │ │ │ │ └── DHxlsReaderIOS.m │ │ │ │ ├── config.h │ │ │ │ ├── cplusplus │ │ │ │ ├── XlsReader.cpp │ │ │ │ ├── XlsReader.h │ │ │ │ └── main11.cpp │ │ │ │ ├── libxls │ │ │ │ ├── brdb.c.h │ │ │ │ ├── brdb.h │ │ │ │ ├── ole.h │ │ │ │ ├── xls.h │ │ │ │ ├── xlsstruct.h │ │ │ │ ├── xlstool.h │ │ │ │ └── xlstypes.h │ │ │ │ └── src │ │ │ │ ├── getopt.c │ │ │ │ ├── ole.c │ │ │ │ ├── xls.c │ │ │ │ ├── xls2csv.c │ │ │ │ └── xlstool.c │ │ └── XLSX │ │ │ ├── SSZipArchive │ │ │ ├── Common.h │ │ │ ├── SSZipArchive.h │ │ │ ├── SSZipArchive.m │ │ │ ├── aes │ │ │ │ ├── aes.h │ │ │ │ ├── aes_via_ace.h │ │ │ │ ├── aescrypt.c │ │ │ │ ├── aeskey.c │ │ │ │ ├── aesopt.h │ │ │ │ ├── aestab.c │ │ │ │ ├── aestab.h │ │ │ │ ├── brg_endian.h │ │ │ │ ├── brg_types.h │ │ │ │ ├── entropy.c │ │ │ │ ├── entropy.h │ │ │ │ ├── fileenc.c │ │ │ │ ├── fileenc.h │ │ │ │ ├── hmac.c │ │ │ │ ├── hmac.h │ │ │ │ ├── prng.c │ │ │ │ ├── prng.h │ │ │ │ ├── pwd2key.c │ │ │ │ ├── pwd2key.h │ │ │ │ ├── sha1.c │ │ │ │ └── sha1.h │ │ │ └── minizip │ │ │ │ ├── crypt.h │ │ │ │ ├── ioapi.c │ │ │ │ ├── ioapi.h │ │ │ │ ├── mztools.c │ │ │ │ ├── mztools.h │ │ │ │ ├── unzip.c │ │ │ │ ├── unzip.h │ │ │ │ ├── zip.c │ │ │ │ └── zip.h │ │ │ ├── ZXLSXParsers注解.m │ │ │ └── xmlParser │ │ │ ├── ZBaseParser.h │ │ │ ├── ZBaseParser.m │ │ │ ├── ZContentParser.h │ │ │ ├── ZContentParser.m │ │ │ ├── ZSheetParser.h │ │ │ ├── ZSheetParser.m │ │ │ ├── ZWorkbookParser.h │ │ │ ├── ZWorkbookParser.m │ │ │ ├── ZXLSXParser.h │ │ │ ├── ZXLSXParser.m │ │ │ ├── config.h │ │ │ └── models │ │ │ ├── ZContent.h │ │ │ ├── ZContent.m │ │ │ ├── ZPaserProtocol.h │ │ │ ├── ZSheet.h │ │ │ ├── ZSheet.m │ │ │ ├── ZSheetCol.h │ │ │ └── ZSheetCol.m │ ├── Info.plist │ └── ViewController.swift ├── test.csv ├── test.xls └── test3.xlsx └── README.md /ExcelDemo/ExcelDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo.xcodeproj/project.xcworkspace/xcuserdata/molangwu.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/molangwu/ExcelParseForIOS/99aa19bbc75d79c991a579f62773037177018494/ExcelDemo/ExcelDemo.xcodeproj/project.xcworkspace/xcuserdata/molangwu.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo.xcodeproj/xcuserdata/molangwu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo.xcodeproj/xcuserdata/molangwu.xcuserdatad/xcschemes/ExcelDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo.xcodeproj/xcuserdata/molangwu.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ExcelDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 187533901F458030007BCC35 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ExcelDemo 4 | // 5 | // Created by molangwu on 2017/8/17. 6 | // Copyright © 2017年 molangwu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | } 43 | ], 44 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelDemoDHlibxls-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'TestDHlibxls' target in the 'TestDHlibxls' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelDemo_Briding_Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // ExcelDemo_Briding_Header.h 3 | // ExcelDemo 4 | // 5 | // Created by molangwu on 2017/8/17. 6 | // Copyright © 2017年 molangwu. All rights reserved. 7 | // 8 | 9 | #ifndef ExcelDemo_Briding_Header_h 10 | #define ExcelDemo_Briding_Header_h 11 | 12 | 13 | #endif /* ExcelDemo_Briding_Header_h */ 14 | 15 | #import "LAWExcelTool.h" 16 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/CSV/CSVParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // CSVParser.h 3 | // ExcelDemo 4 | // 5 | // Created by molangwu on 2017/8/17. 6 | // Copyright © 2017年 molangwu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CSVParser : NSObject 12 | 13 | + (NSMutableArray *)readCSVData:(NSString *)filePath; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/CSV/CSVParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // CSVParser.m 3 | // ExcelDemo 4 | // 5 | // Created by molangwu on 2017/8/17. 6 | // Copyright © 2017年 molangwu. All rights reserved. 7 | // 8 | 9 | #import "CSVParser.h" 10 | 11 | @implementation CSVParser 12 | 13 | + (NSMutableArray *)readCSVData:(NSString *)filePath { 14 | NSMutableArray *_InfoArray; 15 | if (_InfoArray) { 16 | return NULL; 17 | } 18 | _InfoArray=[[NSMutableArray alloc]init]; 19 | 20 | FILE *fp=fopen([filePath UTF8String], "r"); 21 | if (fp) { 22 | // 处理文本信息 转化 成 数组文件 23 | do { 24 | char buf[BUFSIZ]; 25 | fgets(buf, BUFSIZ, fp); 26 | 27 | // 处理文本信息 转化 成 数组文件 28 | NSString *s=[[NSString alloc]initWithUTF8String:(const char *)buf]; 29 | NSString *ss=[s stringByReplacingOccurrencesOfString:@"\r" withString:@""]; 30 | ss=[ss stringByReplacingOccurrencesOfString:@"\n" withString:@""]; 31 | NSArray *a=[ss componentsSeparatedByString:@","]; 32 | 33 | [_InfoArray addObject:a]; 34 | } while (!feof(fp)); 35 | 36 | } 37 | return _InfoArray; 38 | } 39 | @end 40 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/LAWExcelTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // LAWExcelTools.h 3 | // ExcelDemo 4 | // 5 | // Created by molangwu on 2017/8/17. 6 | // Copyright © 2017年 molangwu. All rights reserved. 7 | // Github: https://github.com/molangwu/ExcelParseForIOS.git 8 | // E-mail: 672593619@qq.com 9 | 10 | #import 11 | 12 | @class LAWExcelTool; 13 | @protocol LAWExcelParserDelegate 14 | 15 | @required 16 | 17 | /** 18 | * 处理解析的结果 19 | * 20 | * @param parser 解析器 21 | * @param responseObj 解析结果 22 | * 23 | */ 24 | - (void)parser:(LAWExcelTool *)parser success:(id)responseObj; 25 | 26 | 27 | @end 28 | 29 | @interface LAWExcelTool : NSObject 30 | 31 | @property (nonatomic, weak) id delegate; // 回调处理 32 | 33 | +(LAWExcelTool *) shareInstance; 34 | 35 | -(void) parserExcelWithPath:(NSString *)filePath; 36 | 37 | -(void) parserExcel_XLS_WithPath:(NSString *)filePath; 38 | -(void) parserExcel_XLSX_WithPath:(NSString *)filePath; 39 | -(void) parserExcel_CSV_WithPath:(NSString *)filePath; 40 | 41 | @end 42 | 43 | 44 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/LAWExcelTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // LAWExcelTools.m 3 | // ExcelDemo 4 | // 5 | // Created by molangwu on 2017/8/17. 6 | // Copyright © 2017年 molangwu. All rights reserved. 7 | // 8 | 9 | #import "LAWExcelTool.h" 10 | #import "ZWorkbookParser.h" 11 | #import "ZXLSXParser.h" 12 | #import "ZContent.h" 13 | #import "CSV/CSVParser.h" 14 | #import "DHxlsReaderIOS.h" 15 | 16 | @interface LAWExcelTool() 17 | 18 | @property (nonatomic, strong) ZXLSXParser *xmlPaser; 19 | 20 | @end 21 | 22 | @implementation LAWExcelTool 23 | 24 | // 单例模式 25 | +(LAWExcelTool *)shareInstance { 26 | static LAWExcelTool *instance; 27 | @synchronized(self) { 28 | if(!instance) { 29 | instance = [[LAWExcelTool alloc] init]; 30 | } 31 | } 32 | return instance; 33 | } 34 | 35 | //解析excel 36 | -(void) parserExcelWithPath:(NSString *)filePath { 37 | 38 | NSString *mimeType = [[[filePath componentsSeparatedByString:@"."] lastObject] lowercaseString]; 39 | 40 | if([mimeType isEqualToString:@"csv"]) { 41 | [self parserExcel_CSV_WithPath:filePath]; 42 | } else if ([mimeType isEqualToString:@"xls"]) { 43 | [self parserExcel_XLS_WithPath:filePath]; 44 | } else if ([mimeType isEqualToString:@"xlsx"]) { 45 | [self parserExcel_XLSX_WithPath:filePath]; 46 | } else { 47 | NSLog(@"excel格式不支持"); 48 | } 49 | } 50 | //解析XLSX类型的excel 51 | -(void)parserExcel_XLSX_WithPath:(NSString *)filePath { 52 | _xmlPaser = [ZXLSXParser defaultZXLSXParser]; 53 | [_xmlPaser setParseFilePath:filePath]; 54 | [_xmlPaser setParseOutType:ZParseOutTypeArrayObj]; 55 | _xmlPaser.delegate = self; 56 | [_xmlPaser parse]; 57 | } 58 | //解析XLS类型的excel 59 | -(void)parserExcel_XLS_WithPath:(NSString *)filePath { 60 | NSMutableArray *resultArray = [NSMutableArray array]; 61 | DHxlsReader *reader = [DHxlsReader xlsReaderFromFile:filePath]; 62 | NSString *text = @""; 63 | text = [text stringByAppendingFormat:@"AppName: %@\n", reader.appName]; 64 | text = [text stringByAppendingFormat:@"Author: %@\n", reader.author]; 65 | text = [text stringByAppendingFormat:@"Category: %@\n", reader.category]; 66 | text = [text stringByAppendingFormat:@"Comment: %@\n", reader.comment]; 67 | text = [text stringByAppendingFormat:@"Company: %@\n", reader.company]; 68 | text = [text stringByAppendingFormat:@"Keywords: %@\n", reader.keywords]; 69 | text = [text stringByAppendingFormat:@"LastAuthor: %@\n", reader.lastAuthor]; 70 | text = [text stringByAppendingFormat:@"Manager: %@\n", reader.manager]; 71 | text = [text stringByAppendingFormat:@"Subject: %@\n", reader.subject]; 72 | text = [text stringByAppendingFormat:@"Title: %@\n", reader.title]; 73 | [reader startIterator:0]; 74 | int rows = reader.getRows; 75 | int cols = reader.getCols; 76 | for(int r=1;r<=rows;r++) { 77 | for(int c=1;c<=cols;c++) { 78 | unichar ch =64 + c; 79 | NSString *str =[NSString stringWithUTF8String:(char *)&ch]; 80 | DHcell *cell = [reader cellInWorkSheetIndex:0 row:r col:c]; 81 | ZContent *content = [[ZContent alloc] init]; 82 | content.sheetName = [reader sheetNameAtIndex:0]; 83 | content.keyName = [NSString stringWithFormat: @"%@%d", str,c+r-1]; 84 | content.value = [cell dump]; 85 | [resultArray addObject:content]; 86 | } 87 | } 88 | 89 | __weak typeof(self) weakSelf = self; 90 | 91 | if([_delegate respondsToSelector:@selector(parser:success:)]){ 92 | 93 | [weakSelf.delegate parser:weakSelf success:resultArray]; 94 | }else{ 95 | NSLog(@"delegate is fail...."); 96 | } 97 | 98 | } 99 | 100 | //解析CSV类型的excel 101 | -(void)parserExcel_CSV_WithPath:(NSString *)filePath { 102 | NSMutableArray *result = [CSVParser readCSVData:filePath]; 103 | 104 | NSMutableArray *resultArray = [NSMutableArray array]; 105 | int row = 0; 106 | for(NSArray *item in result) { 107 | 108 | for(int i=0;i 7 | #endif 8 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/DHxlsReaderIOS/DHxlsReaderIOS.h: -------------------------------------------------------------------------------- 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | * 3 | * This file is part of DHlibxls -- permitting code to read Excel(TM) files. 4 | * 5 | * Copyright 2012 David Hoerl All Rights Reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, are 8 | * permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, this list of 11 | * conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 14 | * of conditions and the following disclaimer in the documentation and/or other materials 15 | * provided with the distribution. 16 | * 17 | * 3. Only the ObjectiveC code is under this license - separate license may apply to libxls source. 18 | * Read the documents and source headers in the libxls files which you downloaded earlier. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 22 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | 32 | #import "DHcell.h" 33 | 34 | @interface DHxlsReader : NSObject 35 | 36 | + (DHxlsReader *)xlsReaderFromFile:(NSString *)filePath; 37 | 38 | - (NSString *)libaryVersion; 39 | 40 | // Sheet Information 41 | - (NSUInteger)numberOfSheets; 42 | - (NSString *)sheetNameAtIndex:(NSUInteger)index; 43 | - (BOOL)isSheetVisibleAtIndex:(NSUInteger)index; 44 | 45 | // Random Access 46 | - (DHcell *)cellInWorkSheetIndex:(NSUInteger)sheetNum row:(uint16_t)row col:(uint16_t)col; // uses 1 based indexing! 47 | - (DHcell *)cellInWorkSheetIndex:(NSUInteger)sheetNum row:(uint16_t)row colStr:(char *)col; // "A"...."Z" "AA"..."ZZ" 48 | 49 | // Iterate through all cells 50 | - (void)startIterator:(NSUInteger)sheetNum; 51 | - (DHcell *)nextCell; 52 | 53 | -(int)getRows; 54 | -(int)getCols; 55 | // Summary Information 56 | - (NSString *)appName; 57 | - (NSString *)author; 58 | - (NSString *)category; 59 | - (NSString *)comment; 60 | - (NSString *)company; 61 | - (NSString *)keywords; 62 | - (NSString *)lastAuthor; 63 | - (NSString *)manager; 64 | - (NSString *)subject; 65 | - (NSString *)title; 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.in by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_DLFCN_H 1 6 | 7 | /* Define if you have the iconv() function. */ 8 | #define HAVE_ICONV 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_INTTYPES_H 1 12 | 13 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 14 | to 0 otherwise. */ 15 | #define HAVE_MALLOC 1 16 | 17 | /* Define to 1 if you have the header file. */ 18 | #define HAVE_MEMORY_H 1 19 | 20 | /* Define to 1 if you have the `pow' function. */ 21 | #define HAVE_POW 1 22 | 23 | /* Define to 1 if your system has a GNU libc compatible `realloc' function, 24 | and to 0 otherwise. */ 25 | #define HAVE_REALLOC 1 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #define HAVE_STDINT_H 1 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #define HAVE_STDLIB_H 1 32 | 33 | /* Define to 1 if you have the `strdup' function. */ 34 | #define HAVE_STRDUP 1 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #define HAVE_STRINGS_H 1 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #define HAVE_STRING_H 1 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #define HAVE_SYS_STAT_H 1 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #define HAVE_SYS_TYPES_H 1 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #define HAVE_UNISTD_H 1 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #define HAVE_WCHAR_H 1 53 | 54 | /* Major version */ 55 | #define LIBXLS_MAJOR_VERSION 1 56 | 57 | /* Micro version */ 58 | #define LIBXLS_MICRO_VERSION 0 59 | 60 | /* Minor version */ 61 | #define LIBXLS_MINOR_VERSION 2 62 | 63 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 64 | */ 65 | #define LT_OBJDIR ".libs/" 66 | 67 | /* Name of package */ 68 | #define PACKAGE "libxls" 69 | 70 | /* Define to the address where bug reports for this package should be sent. */ 71 | #define PACKAGE_BUGREPORT "cleit@users.sourceforge.net" 72 | 73 | /* Define to the full name of this package. */ 74 | #define PACKAGE_NAME "libxls" 75 | 76 | /* Define to the full name and version of this package. */ 77 | #define PACKAGE_STRING "libxls 1.0.0" 78 | 79 | /* Define to the one symbol short name of this package. */ 80 | #define PACKAGE_TARNAME "libxls" 81 | 82 | /* Define to the version of this package. */ 83 | #define PACKAGE_VERSION "1.0.0" 84 | 85 | /* Define to 1 if you have the ANSI C header files. */ 86 | #define STDC_HEADERS 1 87 | 88 | /* Version number of package */ 89 | #define VERSION "1.2.0" 90 | 91 | /* Define to empty if `const' does not conform to ANSI C. */ 92 | /* #undef const */ 93 | 94 | /* Define to rpl_malloc if the replacement function should be used. */ 95 | /* #undef malloc */ 96 | 97 | /* Define to rpl_realloc if the replacement function should be used. */ 98 | /* #undef realloc */ 99 | 100 | /* Define to `unsigned int' if does not define. */ 101 | /* #undef size_t */ 102 | 103 | #define HAVE_ASPRINTF 1 104 | 105 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/cplusplus/XlsReader.h: -------------------------------------------------------------------------------- 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | * 3 | * This file is part of libxls -- A multiplatform, C/C++ library 4 | * for parsing Excel(TM) files. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * Copyright 2012 David Hoerl 27 | * 28 | */ 29 | 30 | #include 31 | 32 | #include "xls.h" 33 | 34 | #define XLS_WIDE_STRINGS 0 35 | 36 | #if XLS_WIDE_STRINGS == 0 37 | typedef std::string xlsString; 38 | #else 39 | #include 40 | typedef std::wstring xlsString; 41 | #endif 42 | 43 | namespace xls 44 | { 45 | typedef enum { cellBlank=0, cellString, cellInteger, cellFloat, cellBool, cellError, cellUnknown } contentsType; 46 | 47 | struct cellContent { 48 | contentsType type; 49 | char colStr[3]; // String "A"..."Z", "AA"..."ZZ" (second char is either nil or a capital letter) 50 | uint32_t col; // 1 based 51 | uint16_t row; // 1 based 52 | xlsString str; // even for numbers these values are formatted as well as provided below 53 | union Val { 54 | long l; 55 | double d; 56 | bool b; 57 | int32_t e; 58 | 59 | Val(int x) { l = x; } 60 | ~Val() { } 61 | } val; 62 | 63 | cellContent(void) : 64 | type(cellBlank), 65 | colStr(), 66 | col(0), 67 | row(0), 68 | val(0) { } 69 | ~cellContent() {} 70 | }; 71 | 72 | class WorkBook 73 | { 74 | public: 75 | #if XLS_WIDE_STRINGS == 0 76 | // characterSet is the 8-bit encoding you want to convert 16-bit unicode strings to 77 | WorkBook(const std::string& fileName, int debug=0, const char *characterSet="UTF-8"); 78 | #else 79 | // characterSet has to be UTF-8 80 | WorkBook(const std::string& fileName, int debug=0); 81 | #endif 82 | ~WorkBook(); 83 | 84 | std::string GetLibraryVersion() const; 85 | uint32_t GetSheetCount() const; 86 | 87 | // Sheets 88 | xlsString GetSheetName(uint32_t sheetNum) const; 89 | bool GetSheetVisible(uint32_t sheetNum) const; 90 | 91 | // Summary 92 | xlsString GetSummaryAppName(void) const; 93 | xlsString GetSummaryAuthor(void) const; 94 | xlsString GetSummaryCategory(void) const; 95 | xlsString GetSummaryComment(void) const; 96 | xlsString GetSummaryCompany(void) const; 97 | xlsString GetSummaryKeywords(void) const; 98 | xlsString GetSummaryLastAuthor(void) const; 99 | xlsString GetSummaryManager(void) const; 100 | xlsString GetSummarySubject(void) const; 101 | xlsString GetSummaryTitle(void) const; 102 | 103 | cellContent GetCell(uint32_t workSheetIndex, uint16_t row, uint16_t col); // uses 1 based indexing! 104 | cellContent GetCell(uint32_t workSheetIndex, uint16_t row, const char *colStr); // "A"...."Z" "AA"..."ZZ" 105 | 106 | void InitIterator(uint32_t sheetNum = UINT32_MAX); // call this first... 107 | cellContent GetNextCell(void); // ...then this continually til you get a blank cell 108 | 109 | void ShowCell(const cellContent& content) const; 110 | 111 | private: 112 | WorkBook(const WorkBook& that); 113 | WorkBook& operator=(const WorkBook& right); 114 | 115 | private: 116 | void OpenSheet(uint32_t sheetNum); 117 | void FormatCell(xlsCell *cell, cellContent& content) const; 118 | xlsString char2string(const uint8_t *ptr) const; 119 | #if XLS_WIDE_STRINGS == 1 120 | bool isAscii(const uint8_t *ptr) const; 121 | #endif 122 | 123 | private: 124 | const char *charSet; // must be first ivar 125 | bool isUTF8; // unused in the wstring case 126 | #if XLS_WIDE_STRINGS == 1 127 | iconv_t iconvCD; 128 | #endif 129 | uint32_t numSheets; 130 | xlsWorkBook *workBook; 131 | uint32_t activeWorkSheetID; // keep last one active 132 | xlsWorkSheet *activeWorkSheet; // keep last one active 133 | xlsSummaryInfo *summary; 134 | 135 | bool iterating; 136 | uint32_t lastRowIndex; 137 | uint32_t lastColIndex; 138 | }; 139 | } 140 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/cplusplus/main11.cpp: -------------------------------------------------------------------------------- 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | * 3 | * This file is part of libxls -- A multiplatform, C/C++ library 4 | * for parsing Excel(TM) files. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * Copyright 2012 David Hoerl 27 | * 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "XlsReader.h" 38 | 39 | using namespace xls; 40 | using namespace std; 41 | 42 | //int main(int argc, char *argv[]) 43 | //{ 44 | //#warning Provide a hard coded file path 45 | // string s = string("/tmp/xls.xls"); 46 | // WorkBook foo(s); 47 | // 48 | // cellContent cell = foo.GetCell(0, 1, 2); 49 | // foo.ShowCell(cell); 50 | // 51 | // foo.InitIterator(0); 52 | // while(true) { 53 | // cellContent c = foo.GetNextCell(); 54 | // if(c.type == cellBlank) break; 55 | // foo.ShowCell(c); 56 | // } 57 | //} 58 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/libxls/brdb.c.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/molangwu/ExcelParseForIOS/99aa19bbc75d79c991a579f62773037177018494/ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/libxls/brdb.c.h -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/libxls/brdb.h: -------------------------------------------------------------------------------- 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | * 3 | * This file is part of libxls -- A multiplatform, C/C++ library 4 | * for parsing Excel(TM) files. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * Copyright 2004 Komarov Valery 27 | * Copyright 2006 Christophe Leitienne 28 | * Copyright 2008-2012 David Hoerl 29 | * 30 | */ 31 | 32 | struct str_brdb 33 | { 34 | WORD opcode; 35 | char * name; /* printable name */ 36 | char * desc; /* printable description */ 37 | }; 38 | typedef struct str_brdb record_brdb; 39 | 40 | record_brdb brdb[] = 41 | { 42 | #include "brdb.c.h" 43 | }; 44 | 45 | static int get_brbdnum(int id) 46 | { 47 | 48 | int i; 49 | i=0; 50 | do 51 | { 52 | if (brdb[i].opcode==id) 53 | return i; 54 | i++; 55 | } 56 | while (brdb[i].opcode!=0xFFF); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/libxls/ole.h: -------------------------------------------------------------------------------- 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | * 3 | * This file is part of libxls -- A multiplatform, C/C++ library 4 | * for parsing Excel(TM) files. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * Copyright 2004 Komarov Valery 27 | * Copyright 2006 Christophe Leitienne 28 | * Copyright 2008-2012 David Hoerl 29 | * 30 | */ 31 | 32 | #ifndef OLE_INCLUDE 33 | #define OLE_INCLUDE 34 | 35 | #include // FILE * 36 | 37 | #include "xlstypes.h" 38 | 39 | #pragma pack(push, 1) 40 | 41 | typedef struct TIME_T 42 | { 43 | DWORD LowDate; 44 | DWORD HighDate; 45 | } 46 | TIME_T; 47 | 48 | typedef struct OLE2Header 49 | { 50 | DWORD id[2]; //D0CF11E0 A1B11AE1 51 | DWORD clid[4]; 52 | WORD verminor; //0x3e 53 | WORD verdll; //0x03 54 | WORD byteorder; 55 | WORD lsectorB; 56 | WORD lssectorB; 57 | 58 | WORD reserved1; 59 | DWORD reserved2; 60 | DWORD reserved3; 61 | 62 | DWORD cfat; // count full sectors 63 | DWORD dirstart; 64 | 65 | DWORD reserved4; 66 | 67 | DWORD sectorcutoff; // min size of a standard stream ; if less than this then it uses short-streams 68 | DWORD sfatstart; // first short-sector or EOC 69 | DWORD csfat; // count short sectors 70 | DWORD difstart; // first sector master sector table or EOC 71 | DWORD cdif; // total count 72 | DWORD MSAT[109]; // First 109 MSAT 73 | } 74 | OLE2Header; 75 | 76 | #pragma pack(pop) 77 | 78 | //----------------------------------------------------------------------------------- 79 | typedef struct st_olefiles 80 | { 81 | long count; 82 | struct st_olefiles_data 83 | { 84 | BYTE* name; 85 | DWORD start; 86 | DWORD size; 87 | } 88 | * file; 89 | } 90 | st_olefiles; 91 | 92 | typedef struct OLE2 93 | { 94 | FILE* file; 95 | WORD lsector; 96 | WORD lssector; 97 | DWORD cfat; 98 | DWORD dirstart; 99 | 100 | DWORD sectorcutoff; 101 | DWORD sfatstart; 102 | DWORD csfat; 103 | DWORD difstart; 104 | DWORD cdif; 105 | DWORD* SecID; // regular sector data 106 | DWORD* SSecID; // short sector data 107 | BYTE* SSAT; // directory of short sectors 108 | st_olefiles files; 109 | } 110 | OLE2; 111 | 112 | typedef struct OLE2Stream 113 | { 114 | OLE2* ole; 115 | DWORD start; 116 | size_t pos; 117 | size_t cfat; 118 | size_t size; 119 | size_t fatpos; 120 | BYTE* buf; 121 | DWORD bufsize; 122 | BYTE eof; 123 | BYTE sfat; // short 124 | } 125 | OLE2Stream; 126 | 127 | #pragma pack(push, 1) 128 | 129 | typedef struct PSS 130 | { 131 | BYTE name[64]; 132 | WORD bsize; 133 | BYTE type; //STGTY 134 | #define PS_EMPTY 00 135 | #define PS_USER_STORAGE 01 136 | #define PS_USER_STREAM 02 137 | #define PS_USER_ROOT 05 138 | BYTE flag; //COLOR 139 | #define BLACK 1 140 | DWORD left; 141 | DWORD right; 142 | DWORD child; 143 | WORD guid[8]; 144 | DWORD userflags; 145 | TIME_T time[2]; 146 | DWORD sstart; 147 | DWORD size; 148 | DWORD proptype; 149 | } 150 | PSS; 151 | 152 | #pragma pack(pop) 153 | 154 | extern size_t ole2_read(void* buf,size_t size,size_t count,OLE2Stream* olest); 155 | extern OLE2Stream* ole2_sopen(OLE2* ole,DWORD start, size_t size); 156 | extern void ole2_seek(OLE2Stream* olest,DWORD ofs); 157 | extern OLE2Stream* ole2_fopen(OLE2* ole,BYTE* file); 158 | extern void ole2_fclose(OLE2Stream* ole2st); 159 | extern OLE2* ole2_open(const BYTE *file); 160 | extern void ole2_close(OLE2* ole2); 161 | extern void ole2_bufread(OLE2Stream* olest); 162 | 163 | 164 | #endif 165 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/libxls/xls.h: -------------------------------------------------------------------------------- 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | * 3 | * This file is part of libxls -- A multiplatform, C/C++ library 4 | * for parsing Excel(TM) files. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * Copyright 2004 Komarov Valery 27 | * Copyright 2006 Christophe Leitienne 28 | * Copyright 2008-2012 David Hoerl 29 | * 30 | */ 31 | 32 | #ifndef XLS_INCLUDE 33 | #define XLS_INCLUDE 34 | 35 | #ifdef __cplusplus 36 | namespace xls { 37 | extern "C" { 38 | #endif 39 | 40 | #include "xlstypes.h" 41 | #include "xlsstruct.h" 42 | #include "xlstool.h" 43 | 44 | 45 | #define BLANK_CELL 0x0201 46 | 47 | 48 | extern const char* xls_getVersion(void); 49 | 50 | extern int xls(int debug); // Set debug. Force library to load? 51 | 52 | extern void xls_parseWorkBook(xlsWorkBook* pWB); 53 | extern void xls_parseWorkSheet(xlsWorkSheet* pWS); 54 | 55 | extern xlsWorkBook* xls_open(const char *file,const char *charset); // convert 16bit strings within the spread sheet to this 8-bit encoding (UTF-8 default) 56 | #define xls_close xls_close_WB // historical 57 | extern void xls_close_WB(xlsWorkBook* pWB); // preferred name 58 | 59 | extern xlsWorkSheet * xls_getWorkSheet(xlsWorkBook* pWB,int num); 60 | extern void xls_close_WS(xlsWorkSheet* pWS); 61 | 62 | extern xlsSummaryInfo *xls_summaryInfo(xlsWorkBook* pWB); 63 | extern void xls_close_summaryInfo(xlsSummaryInfo *pSI); 64 | 65 | // utility function 66 | xlsRow *xls_row(xlsWorkSheet* pWS, WORD cellRow); 67 | xlsCell *xls_cell(xlsWorkSheet* pWS, WORD cellRow, WORD cellCol); 68 | 69 | #ifdef __cplusplus 70 | } // extern c block 71 | } // namespace 72 | #endif 73 | 74 | #endif 75 | 76 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/libxls/xlsstruct.h: -------------------------------------------------------------------------------- 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | * 3 | * This file is part of libxls -- A multiplatform, C/C++ library 4 | * for parsing Excel(TM) files. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * Copyright 2004 Komarov Valery 27 | * Copyright 2006 Christophe Leitienne 28 | * Copyright 2008-2012 David Hoerl 29 | * 30 | */ 31 | 32 | #ifndef XLS_STRUCT_INC 33 | #define XLS_STRUCT_INC 34 | 35 | #include "ole.h" 36 | 37 | #pragma pack(push, 1) 38 | 39 | typedef struct BOF 40 | { 41 | WORD id; 42 | WORD size; 43 | } 44 | BOF; 45 | 46 | typedef struct BIFF 47 | { 48 | WORD ver; 49 | WORD type; 50 | WORD id_make; 51 | WORD year; 52 | DWORD flags; 53 | DWORD min_ver; 54 | BYTE buf[100]; 55 | } 56 | BIFF; 57 | 58 | typedef struct WIND1 59 | { 60 | WORD xWn; 61 | WORD yWn; 62 | WORD dxWn; 63 | WORD dyWn; 64 | WORD grbit; 65 | WORD itabCur; 66 | WORD itabFirst; 67 | WORD ctabSel; 68 | WORD wTabRatio; 69 | } 70 | WIND1; 71 | 72 | typedef struct BOUNDSHEET 73 | { 74 | DWORD filepos; 75 | BYTE type; 76 | BYTE visible; 77 | BYTE name[]; 78 | } 79 | BOUNDSHEET; 80 | 81 | typedef struct ROW 82 | { 83 | WORD index; 84 | WORD fcell; 85 | WORD lcell; 86 | WORD height; 87 | WORD notused; 88 | WORD notused2; //used only for BIFF3-4 89 | WORD flags; 90 | WORD xf; 91 | } 92 | ROW; 93 | 94 | typedef struct COL 95 | { 96 | WORD row; 97 | WORD col; 98 | WORD xf; 99 | } 100 | COL; 101 | 102 | 103 | typedef struct FORMULA // BIFF8 104 | { 105 | WORD row; 106 | WORD col; 107 | WORD xf; 108 | // ULLONG res; 109 | BYTE resid; 110 | BYTE resdata[5]; 111 | WORD res; 112 | // double res; 113 | WORD flags; 114 | BYTE chn[4]; // BIFF8 115 | WORD len; 116 | BYTE value[1]; //var 117 | } 118 | FORMULA; 119 | 120 | typedef struct RK 121 | { 122 | WORD row; 123 | WORD col; 124 | WORD xf; 125 | BYTE value[1]; // var 126 | } 127 | RK; 128 | 129 | typedef struct BLANK 130 | { 131 | WORD row; 132 | WORD col; 133 | WORD xf; 134 | } 135 | BLANK; 136 | 137 | typedef struct LABEL 138 | { 139 | WORD row; 140 | WORD col; 141 | WORD xf; 142 | BYTE value[1]; // var 143 | } 144 | LABEL; 145 | typedef LABEL LABELSST; 146 | 147 | typedef struct SST 148 | { 149 | DWORD num; 150 | DWORD numofstr; 151 | BYTE strings; 152 | } 153 | SST; 154 | 155 | typedef struct XF5 156 | { 157 | WORD font; 158 | WORD format; 159 | WORD type; 160 | WORD align; 161 | WORD color; 162 | WORD fill; 163 | WORD border; 164 | WORD linestyle; 165 | } 166 | XF5; 167 | 168 | typedef struct XF8 169 | { 170 | WORD font; 171 | WORD format; 172 | WORD type; 173 | BYTE align; 174 | BYTE rotation; 175 | BYTE ident; 176 | BYTE usedattr; 177 | DWORD linestyle; 178 | DWORD linecolor; 179 | WORD groundcolor; 180 | } 181 | XF8; 182 | 183 | typedef struct BR_NUMBER 184 | { 185 | WORD row; 186 | WORD col; 187 | WORD xf; 188 | double value; 189 | } 190 | BR_NUMBER; 191 | 192 | typedef struct COLINFO 193 | { 194 | WORD first; 195 | WORD last; 196 | WORD width; 197 | WORD xf; 198 | WORD flags; 199 | WORD notused; 200 | } 201 | COLINFO; 202 | 203 | typedef struct MERGEDCELLS 204 | { 205 | WORD rowf; 206 | WORD rowl; 207 | WORD colf; 208 | WORD coll; 209 | } 210 | MERGEDCELLS; 211 | 212 | typedef struct FONT 213 | { 214 | WORD height; 215 | WORD flag; 216 | WORD color; 217 | WORD bold; 218 | WORD escapement; 219 | BYTE underline; 220 | BYTE family; 221 | BYTE charset; 222 | BYTE notused; 223 | BYTE name; 224 | } 225 | FONT; 226 | 227 | typedef struct FORMAT 228 | { 229 | WORD index; 230 | BYTE value[0]; 231 | } 232 | FORMAT; 233 | 234 | #pragma pack(pop) 235 | 236 | //--------------------------------------------------------- 237 | 238 | typedef struct st_sheet 239 | { 240 | DWORD count; //Count of sheets 241 | struct st_sheet_data 242 | { 243 | DWORD filepos; 244 | BYTE visibility; 245 | BYTE type; 246 | BYTE* name; 247 | } 248 | * sheet; 249 | } 250 | st_sheet; 251 | 252 | typedef struct st_font 253 | { 254 | DWORD count; //Count of FONT's 255 | struct st_font_data 256 | { 257 | WORD height; 258 | WORD flag; 259 | WORD color; 260 | WORD bold; 261 | WORD escapement; 262 | BYTE underline; 263 | BYTE family; 264 | BYTE charset; 265 | BYTE* name; 266 | } 267 | * font; 268 | } 269 | st_font; 270 | 271 | typedef struct st_format 272 | { 273 | DWORD count; //Count of FORMAT's 274 | struct st_format_data 275 | { 276 | WORD index; 277 | BYTE *value; 278 | } 279 | * format; 280 | } 281 | st_format; 282 | 283 | typedef struct st_xf 284 | { 285 | DWORD count; //Count of XF 286 | // XF** xf; 287 | struct st_xf_data 288 | { 289 | WORD font; 290 | WORD format; 291 | WORD type; 292 | BYTE align; 293 | BYTE rotation; 294 | BYTE ident; 295 | BYTE usedattr; 296 | DWORD linestyle; 297 | DWORD linecolor; 298 | WORD groundcolor; 299 | } 300 | * xf; 301 | } 302 | st_xf; 303 | 304 | 305 | typedef struct st_sst 306 | { 307 | DWORD count; 308 | DWORD lastid; 309 | DWORD continued; 310 | DWORD lastln; 311 | DWORD lastrt; 312 | DWORD lastsz; 313 | struct str_sst_string 314 | { 315 | BYTE* str; 316 | } 317 | * string; 318 | } 319 | st_sst; 320 | 321 | 322 | typedef struct st_cell 323 | { 324 | DWORD count; 325 | struct st_cell_data 326 | { 327 | WORD id; 328 | WORD row; 329 | WORD col; 330 | WORD xf; 331 | BYTE* str; // String value; 332 | double d; 333 | int32_t l; 334 | WORD width; // Width of col 335 | WORD colspan; 336 | WORD rowspan; 337 | BYTE isHidden; // Is cell hidden 338 | } 339 | * cell; 340 | } 341 | st_cell; 342 | 343 | 344 | typedef struct st_row 345 | { 346 | // DWORD count; 347 | WORD lastcol; // numCols - 1 348 | WORD lastrow; // numRows - 1 349 | struct st_row_data 350 | { 351 | WORD index; 352 | WORD fcell; 353 | WORD lcell; 354 | WORD height; 355 | WORD flags; 356 | WORD xf; 357 | BYTE xfflags; 358 | st_cell cells; 359 | } 360 | * row; 361 | } 362 | st_row; 363 | 364 | 365 | typedef struct st_colinfo 366 | { 367 | DWORD count; //Count of COLINFO 368 | struct st_colinfo_data 369 | { 370 | WORD first; 371 | WORD last; 372 | WORD width; 373 | WORD xf; 374 | WORD flags; 375 | } 376 | * col; 377 | } 378 | st_colinfo; 379 | 380 | typedef struct xlsWorkBook 381 | { 382 | //FILE* file; // 383 | OLE2Stream* olestr; 384 | int32_t filepos; //position in file 385 | 386 | //From Header (BIFF) 387 | BYTE is5ver; 388 | WORD type; 389 | 390 | //Other data 391 | WORD codepage; //Charset codepage 392 | char* charset; 393 | st_sheet sheets; 394 | st_sst sst; //SST table 395 | st_xf xfs; //XF table 396 | st_font fonts; 397 | st_format formats; //FORMAT table 398 | 399 | char *summary; // ole file 400 | char *docSummary; // ole file 401 | } 402 | xlsWorkBook; 403 | 404 | typedef struct xlsWorkSheet 405 | { 406 | DWORD filepos; 407 | WORD defcolwidth; 408 | st_row rows; 409 | xlsWorkBook *workbook; 410 | st_colinfo colinfo; 411 | } 412 | xlsWorkSheet; 413 | 414 | #ifdef __cplusplus 415 | typedef struct st_cell::st_cell_data xlsCell; 416 | typedef struct st_row::st_row_data xlsRow; 417 | #else 418 | typedef struct st_cell_data xlsCell; 419 | typedef struct st_row_data xlsRow; 420 | #endif 421 | 422 | typedef struct xls_summaryInfo 423 | { 424 | BYTE *title; 425 | BYTE *subject; 426 | BYTE *author; 427 | BYTE *keywords; 428 | BYTE *comment; 429 | BYTE *lastAuthor; 430 | BYTE *appName; 431 | BYTE *category; 432 | BYTE *manager; 433 | BYTE *company; 434 | } 435 | xlsSummaryInfo; 436 | 437 | #endif 438 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/libxls/xlstool.h: -------------------------------------------------------------------------------- 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | * 3 | * This file is part of libxls -- A multiplatform, C/C++ library 4 | * for parsing Excel(TM) files. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * Copyright 2004 Komarov Valery 27 | * Copyright 2006 Christophe Leitienne 28 | * Copyright 2008-2012 David Hoerl 29 | * 30 | */ 31 | 32 | #include "xlsstruct.h" 33 | 34 | extern void dumpbuf(BYTE* fname,long size,BYTE* buf); 35 | extern void verbose(char* str); 36 | 37 | extern BYTE *utf8_decode(BYTE *str, DWORD len, char *encoding); 38 | extern BYTE* unicode_decode(const BYTE *s, int len, size_t *newlen, const char* encoding); 39 | extern BYTE* get_string(BYTE *s,BYTE is2, BYTE isUnicode, char *charset); 40 | extern DWORD xls_getColor(const WORD color,WORD def); 41 | 42 | extern void xls_showBookInfo(xlsWorkBook* pWB); 43 | extern void xls_showROW(struct st_row_data* row); 44 | extern void xls_showColinfo(struct st_colinfo_data* col); 45 | extern void xls_showCell(struct st_cell_data* cell); 46 | extern void xls_showFont(struct st_font_data* font); 47 | extern void xls_showXF(XF8* xf); 48 | extern void xls_showFormat(struct st_format_data* format); 49 | extern BYTE* xls_getfcell(xlsWorkBook* pWB,struct st_cell_data* cell); 50 | extern char* xls_getCSS(xlsWorkBook* pWB); 51 | extern void xls_showBOF(BOF* bof); 52 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/libxls/xlstypes.h: -------------------------------------------------------------------------------- 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | * 3 | * This file is part of libxls -- A multiplatform, C/C++ library 4 | * for parsing Excel(TM) files. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * Copyright 2004 Komarov Valery 27 | * Copyright 2006 Christophe Leitienne 28 | * Copyright 2008-2012 David Hoerl 29 | * 30 | */ 31 | 32 | #ifndef XLS_TYPES_INC 33 | #define XLS_TYPES_INC 34 | 35 | #include 36 | 37 | typedef unsigned char BYTE; 38 | typedef uint16_t WORD; 39 | typedef uint32_t DWORD; 40 | 41 | typedef uint16_t WORD_UA __attribute__ ((aligned (1))); // 2 bytes 42 | typedef uint32_t DWORD_UA __attribute__ ((aligned (1))); // 4 bytes 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/src/getopt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987, 1993, 1994 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the University of 16 | * California, Berkeley and its contributors. 17 | * 4. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | */ 33 | 34 | #if defined(LIBC_SCCS) && !defined(lint) 35 | /* static char sccsid[] = "from: @(#)getopt.c 8.2 (Berkeley) 4/2/94"; */ 36 | static char *rcsid = "$Id: getopt.c,v 1.2 1998/01/21 22:27:05 billm Exp $"; 37 | #endif /* LIBC_SCCS and not lint */ 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | int opterr = 1, /* if error message should be printed */ 44 | optind = 1, /* index into parent argv vector */ 45 | optopt, /* character checked for validity */ 46 | optreset; /* reset getopt */ 47 | char *optarg; /* argument associated with option */ 48 | 49 | #define BADCH (int)'?' 50 | #define BADARG (int)':' 51 | #define EMSG "" 52 | 53 | extern int getopt(int nargc, char * const *nargv, const char *ostr); 54 | 55 | /* 56 | * getopt -- 57 | * Parse argc/argv argument vector. 58 | */ 59 | int 60 | getopt( 61 | int nargc, 62 | char * const *nargv, 63 | const char *ostr 64 | ) { 65 | static char *place = EMSG; /* option letter processing */ 66 | char *oli; /* option letter list index */ 67 | 68 | if (optreset || !*place) { /* update scanning pointer */ 69 | optreset = 0; 70 | if (optind >= nargc || *(place = nargv[optind]) != '-') { 71 | place = EMSG; 72 | return (-1); 73 | } 74 | if (place[1] && *++place == '-') { /* found "--" */ 75 | ++optind; 76 | place = EMSG; 77 | return (-1); 78 | } 79 | } /* option letter okay? */ 80 | if ((optopt = (int)*place++) == (int)':' || 81 | !(oli = strchr(ostr, optopt))) { 82 | /* 83 | * if the user didn't specify '-' as an option, 84 | * assume it means -1. 85 | */ 86 | if (optopt == (int)'-') 87 | return (-1); 88 | if (!*place) 89 | ++optind; 90 | if (opterr && *ostr != ':') 91 | (void)fprintf(stderr, 92 | "%s: illegal option -- %c\n", nargv[0], optopt); 93 | return (BADCH); 94 | } 95 | if (*++oli != ':') { /* don't need argument */ 96 | optarg = NULL; 97 | if (!*place) 98 | ++optind; 99 | } 100 | else { /* need an argument */ 101 | if (*place) /* no white space */ 102 | optarg = place; 103 | else if (nargc <= ++optind) { /* no arg */ 104 | place = EMSG; 105 | if (*ostr == ':') 106 | return (BADARG); 107 | if (opterr) 108 | (void)fprintf(stderr, 109 | "%s: option requires an argument -- %c\n", 110 | nargv[0], optopt); 111 | return (BADCH); 112 | } 113 | else /* white space */ 114 | optarg = nargv[optind]; 115 | place = EMSG; 116 | ++optind; 117 | } 118 | return (optopt); /* dump back option letter */ 119 | } 120 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLS/DHxlsReader/src/xls2csv.c: -------------------------------------------------------------------------------- 1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 | * 3 | * This file is part of libxls -- A multiplatform, C/C++ library 4 | * for parsing Excel(TM) files. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * Copyright 2006 Christophe Leitienne 27 | * Copyright 2008-2012 David Hoerl 28 | * 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "xls.h" 38 | 39 | static char stringSeparator = '\"'; 40 | static char *lineSeparator = "\n"; 41 | static char *fieldSeparator = ";"; 42 | static char *encoding = "UTF-8"; 43 | 44 | 45 | static void OutputString(const char *string); 46 | static void OutputNumber(const double number); 47 | static void Usage(char *progName); 48 | 49 | static void Usage(char *progName) 50 | { 51 | fprintf(stderr, "usage: %s [-l] [-e encoding] [-t sheet] [-q quote char] [-f field separator]\n", progName); 52 | fprintf(stderr, " Output Excel file cells as delimited values (default is comma separated)\n"); 53 | fprintf(stderr, " Options:\n"); 54 | fprintf(stderr, " -l : list the sheets contained in the file but do not output their contents.\n"); 55 | fprintf(stderr, " -t sheet_name : only process the named sheet\n"); 56 | fprintf(stderr, " -e encoding : the iconv encoding (default \"%s\")\n", encoding); 57 | fprintf(stderr, " -q character : used to quote strings (default '%c')\n", stringSeparator); 58 | fprintf(stderr, " -f string : used to separate fields (default \"%s\")\n", fieldSeparator); 59 | fprintf(stderr, "\n"); 60 | exit(EXIT_FAILURE); 61 | } 62 | 63 | extern int getopt(int nargc, char * const *nargv, const char *ostr); 64 | 65 | int main1(int argc, char *argv[]) { 66 | xlsWorkBook* pWB; 67 | xlsWorkSheet* pWS; 68 | unsigned int i; 69 | int justList = 0; 70 | char *sheetName = ""; 71 | 72 | if(argc < 2) { 73 | Usage(argv[0]); 74 | } 75 | 76 | optind = 2; // skip file arg 77 | 78 | int ch; 79 | while ((ch = getopt(argc, argv, "lt:e:q:f:")) != -1) { 80 | switch (ch) { 81 | case 'l': 82 | justList = 1; 83 | break; 84 | case 'e': 85 | encoding = strdup(optarg); 86 | break; 87 | case 't': 88 | sheetName = strdup(optarg); 89 | break; 90 | case 'q': 91 | stringSeparator = optarg[0]; 92 | break; 93 | case 'f': 94 | fieldSeparator = strdup(optarg); 95 | break; 96 | default: 97 | Usage(argv[0]); 98 | break; 99 | } 100 | } 101 | 102 | struct st_row_data* row; 103 | WORD cellRow, cellCol; 104 | 105 | // open workbook, choose standard conversion 106 | pWB = xls_open(argv[1], encoding); 107 | if (!pWB) { 108 | fprintf(stderr, "File not found"); 109 | fprintf(stderr, "\n"); 110 | return EXIT_FAILURE; 111 | } 112 | 113 | // check if the requested sheet (if any) exists 114 | if (sheetName[0]) { 115 | for (i = 0; i < pWB->sheets.count; i++) { 116 | if (strcmp(sheetName, pWB->sheets.sheet[i].name) == 0) { 117 | break; 118 | } 119 | } 120 | 121 | if (i == pWB->sheets.count) { 122 | fprintf(stderr, "Sheet \"%s\" not found", sheetName); 123 | fprintf(stderr, "\n"); 124 | return EXIT_FAILURE; 125 | } 126 | } 127 | 128 | // process all sheets 129 | for (i = 0; i < pWB->sheets.count; i++) { 130 | int isFirstLine = 1; 131 | 132 | // just looking for sheet names 133 | if (justList) { 134 | printf("%s\n", pWB->sheets.sheet[i].name); 135 | continue; 136 | } 137 | 138 | // check if this the sheet we want 139 | if (sheetName[0]) { 140 | if (strcmp(sheetName, pWB->sheets.sheet[i].name) != 0) { 141 | continue; 142 | } 143 | } 144 | 145 | // open and parse the sheet 146 | pWS = xls_getWorkSheet(pWB, i); 147 | xls_parseWorkSheet(pWS); 148 | 149 | // process all rows of the sheet 150 | for (cellRow = 0; cellRow <= pWS->rows.lastrow; cellRow++) { 151 | int isFirstCol = 1; 152 | row = xls_row(pWS, cellRow); 153 | 154 | // process cells 155 | if (!isFirstLine) { 156 | printf("%s", lineSeparator); 157 | } else { 158 | isFirstLine = 0; 159 | } 160 | 161 | for (cellCol = 0; cellCol <= pWS->rows.lastcol; cellCol++) { 162 | //printf("Processing row=%d col=%d\n", cellRow+1, cellCol+1); 163 | 164 | xlsCell *cell = xls_cell(pWS, cellRow, cellCol); 165 | 166 | if ((!cell) || (cell->isHidden)) { 167 | continue; 168 | } 169 | 170 | if (!isFirstCol) { 171 | printf("%s", fieldSeparator); 172 | } else { 173 | isFirstCol = 0; 174 | } 175 | 176 | // display the colspan as only one cell, but reject rowspans (they can't be converted to CSV) 177 | if (cell->rowspan > 1) { 178 | fprintf(stderr, "Warning: %d rows spanned at col=%d row=%d: output will not match the Excel file.\n", cell->rowspan, cellCol+1, cellRow+1); 179 | } 180 | 181 | // display the value of the cell (either numeric or string) 182 | if (cell->id == 0x27e || cell->id == 0x0BD || cell->id == 0x203) { 183 | OutputNumber(cell->d); 184 | } else if (cell->id == 0x06) { 185 | // formula 186 | if (cell->l == 0) // its a number 187 | { 188 | OutputNumber(cell->d); 189 | } else { 190 | if (!strcmp(cell->str, "bool")) // its boolean, and test cell->d 191 | { 192 | OutputString((int) cell->d ? "true" : "false"); 193 | } else if (!strcmp(cell->str, "error")) // formula is in error 194 | { 195 | OutputString("*error*"); 196 | } else // ... cell->str is valid as the result of a string formula. 197 | { 198 | OutputString(cell->str); 199 | } 200 | } 201 | } else if (cell->str != NULL) { 202 | OutputString(cell->str); 203 | } else { 204 | OutputString(""); 205 | } 206 | } 207 | } 208 | xls_close_WS(pWS); 209 | } 210 | 211 | xls_close(pWB); 212 | return EXIT_SUCCESS; 213 | } 214 | 215 | // Output a CSV String (between double quotes) 216 | // Escapes (doubles)" and \ characters 217 | static void OutputString(const char *string) { 218 | const char *str; 219 | 220 | printf("%c", stringSeparator); 221 | for (str = string; *str; str++) { 222 | if (*str == stringSeparator) { 223 | printf("%c%c", stringSeparator, stringSeparator); 224 | } else if (*str == '\\') { 225 | printf("\\\\"); 226 | } else { 227 | printf("%c", *str); 228 | } 229 | } 230 | printf("%c", stringSeparator); 231 | } 232 | 233 | // Output a CSV Number 234 | static void OutputNumber(const double number) { 235 | printf("%.15g", number); 236 | } 237 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/Common.h: -------------------------------------------------------------------------------- 1 | #ifndef SSZipCommon 2 | #define SSZipCommon 3 | 4 | /* tm_unz contain date/time info */ 5 | typedef struct tm_unz_s 6 | { 7 | unsigned int tm_sec; /* seconds after the minute - [0,59] */ 8 | unsigned int tm_min; /* minutes after the hour - [0,59] */ 9 | unsigned int tm_hour; /* hours since midnight - [0,23] */ 10 | unsigned int tm_mday; /* day of the month - [1,31] */ 11 | unsigned int tm_mon; /* months since January - [0,11] */ 12 | unsigned int tm_year; /* years - [1980..2044] */ 13 | } tm_unz; 14 | 15 | typedef struct unz_file_info_s 16 | { 17 | unsigned long version; /* version made by 2 bytes */ 18 | unsigned long version_needed; /* version needed to extract 2 bytes */ 19 | unsigned long flag; /* general purpose bit flag 2 bytes */ 20 | unsigned long compression_method; /* compression method 2 bytes */ 21 | unsigned long dosDate; /* last mod file date in Dos fmt 4 bytes */ 22 | unsigned long crc; /* crc-32 4 bytes */ 23 | unsigned long compressed_size; /* compressed size 4 bytes */ 24 | unsigned long uncompressed_size; /* uncompressed size 4 bytes */ 25 | unsigned long size_filename; /* filename length 2 bytes */ 26 | unsigned long size_file_extra; /* extra field length 2 bytes */ 27 | unsigned long size_file_comment; /* file comment length 2 bytes */ 28 | 29 | unsigned long disk_num_start; /* disk number start 2 bytes */ 30 | unsigned long internal_fa; /* internal file attributes 2 bytes */ 31 | unsigned long external_fa; /* external file attributes 4 bytes */ 32 | 33 | tm_unz tmu_date; 34 | } unz_file_info; 35 | 36 | /* unz_file_info contain information about a file in the zipfile */ 37 | typedef struct unz_file_info64_s 38 | { 39 | unsigned long version; /* version made by 2 bytes */ 40 | unsigned long version_needed; /* version needed to extract 2 bytes */ 41 | unsigned long flag; /* general purpose bit flag 2 bytes */ 42 | unsigned long compression_method; /* compression method 2 bytes */ 43 | unsigned long dosDate; /* last mod file date in Dos fmt 4 bytes */ 44 | unsigned long crc; /* crc-32 4 bytes */ 45 | unsigned long long compressed_size; /* compressed size 8 bytes */ 46 | unsigned long long uncompressed_size; /* uncompressed size 8 bytes */ 47 | unsigned long size_filename; /* filename length 2 bytes */ 48 | unsigned long size_file_extra; /* extra field length 2 bytes */ 49 | unsigned long size_file_comment; /* file comment length 2 bytes */ 50 | 51 | unsigned long disk_num_start; /* disk number start 2 bytes */ 52 | unsigned long internal_fa; /* internal file attributes 2 bytes */ 53 | unsigned long external_fa; /* external file attributes 4 bytes */ 54 | 55 | tm_unz tmu_date; 56 | unsigned long long disk_offset; 57 | unsigned long size_file_extra_internal; 58 | } unz_file_info64; 59 | 60 | typedef struct unz_global_info_s 61 | { 62 | unsigned long number_entry; /* total number of entries in 63 | the central dir on this disk */ 64 | 65 | unsigned long number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/ 66 | 67 | 68 | unsigned long size_comment; /* size of the global comment of the zipfile */ 69 | } unz_global_info; 70 | 71 | typedef struct unz_global_info64 72 | { 73 | unsigned long long number_entry; /* total number of entries in 74 | the central dir on this disk */ 75 | 76 | unsigned long number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/ 77 | 78 | unsigned long size_comment; /* size of the global comment of the zipfile */ 79 | } unz_global_info64; 80 | 81 | #endif -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/SSZipArchive.h: -------------------------------------------------------------------------------- 1 | // 2 | // SSZipArchive.h 3 | // SSZipArchive 4 | // 5 | // Created by Sam Soffes on 7/21/10. 6 | // Copyright (c) Sam Soffes 2010-2015. All rights reserved. 7 | // 8 | 9 | #ifndef _SSZIPARCHIVE_H 10 | #define _SSZIPARCHIVE_H 11 | 12 | #import 13 | #include "Common.h" 14 | 15 | @protocol SSZipArchiveDelegate; 16 | 17 | @interface SSZipArchive : NSObject 18 | 19 | // Unzip 20 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination; 21 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(id)delegate; 22 | 23 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError * *)error; 24 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError * *)error delegate:(id)delegate; 25 | 26 | + (BOOL)unzipFileAtPath:(NSString *)path 27 | toDestination:(NSString *)destination 28 | progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler 29 | completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError *error))completionHandler; 30 | 31 | + (BOOL)unzipFileAtPath:(NSString *)path 32 | toDestination:(NSString *)destination 33 | overwrite:(BOOL)overwrite 34 | password:(NSString *)password 35 | progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler 36 | completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError *error))completionHandler; 37 | 38 | // Zip 39 | 40 | // without password 41 | + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths; 42 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath; 43 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirector; 44 | 45 | // with password, password could be nil 46 | + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths withPassword:(NSString *)password; 47 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(NSString *)password; 48 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(NSString *)password; 49 | 50 | - (instancetype)initWithPath:(NSString *)path; 51 | @property (NS_NONATOMIC_IOSONLY, readonly) BOOL open; 52 | - (BOOL)writeFile:(NSString *)path withPassword:(NSString *)password; 53 | - (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(NSString *)password; 54 | - (BOOL)writeFileAtPath:(NSString *)path withFileName:(NSString *)fileName withPassword:(NSString *)password; 55 | - (BOOL)writeData:(NSData *)data filename:(NSString *)filename withPassword:(NSString *)password; 56 | @property (NS_NONATOMIC_IOSONLY, readonly) BOOL close; 57 | 58 | @end 59 | 60 | @protocol SSZipArchiveDelegate 61 | 62 | @optional 63 | 64 | - (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo; 65 | - (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath; 66 | 67 | - (BOOL)zipArchiveShouldUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; 68 | - (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; 69 | - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; 70 | - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath unzippedFilePath:(NSString *)unzippedFilePath; 71 | 72 | - (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total; 73 | - (void)zipArchiveDidUnzipArchiveFile:(NSString *)zipFile entryPath:(NSString *)entryPath destPath:(NSString *)destPath; 74 | 75 | @end 76 | 77 | #endif /* _SSZIPARCHIVE_H */ 78 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/aes.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This file contains the definitions required to use AES in C. See aesopt.h 21 | for optimisation details. 22 | */ 23 | 24 | #ifndef _AES_H 25 | #define _AES_H 26 | 27 | #include 28 | 29 | /* This include is used to find 8 & 32 bit unsigned integer types */ 30 | #include "brg_types.h" 31 | 32 | #if defined(__cplusplus) 33 | extern "C" 34 | { 35 | #endif 36 | 37 | #define AES_128 /* if a fast 128 bit key scheduler is needed */ 38 | #define AES_192 /* if a fast 192 bit key scheduler is needed */ 39 | #define AES_256 /* if a fast 256 bit key scheduler is needed */ 40 | #define AES_VAR /* if variable key size scheduler is needed */ 41 | #define AES_MODES /* if support is needed for modes */ 42 | 43 | /* The following must also be set in assembler files if being used */ 44 | 45 | #define AES_ENCRYPT /* if support for encryption is needed */ 46 | #define AES_DECRYPT /* if support for decryption is needed */ 47 | #define AES_REV_DKS /* define to reverse decryption key schedule */ 48 | 49 | #define AES_BLOCK_SIZE 16 /* the AES block size in bytes */ 50 | #define N_COLS 4 /* the number of columns in the state */ 51 | 52 | /* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */ 53 | /* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */ 54 | /* or 44, 52 or 60 32-bit words. */ 55 | 56 | #if defined( AES_VAR ) || defined( AES_256 ) 57 | #define KS_LENGTH 60 58 | #elif defined( AES_192 ) 59 | #define KS_LENGTH 52 60 | #else 61 | #define KS_LENGTH 44 62 | #endif 63 | 64 | #define AES_RETURN INT_RETURN 65 | 66 | /* the character array 'inf' in the following structures is used */ 67 | /* to hold AES context information. This AES code uses cx->inf.b[0] */ 68 | /* to hold the number of rounds multiplied by 16. The other three */ 69 | /* elements can be used by code that implements additional modes */ 70 | 71 | typedef union 72 | { uint_32t l; 73 | uint_8t b[4]; 74 | } aes_inf; 75 | 76 | typedef struct 77 | { uint_32t ks[KS_LENGTH]; 78 | aes_inf inf; 79 | } aes_encrypt_ctx; 80 | 81 | typedef struct 82 | { uint_32t ks[KS_LENGTH]; 83 | aes_inf inf; 84 | } aes_decrypt_ctx; 85 | 86 | /* This routine must be called before first use if non-static */ 87 | /* tables are being used */ 88 | 89 | AES_RETURN aes_init(void); 90 | 91 | /* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */ 92 | /* those in the range 128 <= key_len <= 256 are given in bits */ 93 | 94 | #if defined( AES_ENCRYPT ) 95 | 96 | #if defined( AES_128 ) || defined( AES_VAR) 97 | AES_RETURN aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]); 98 | #endif 99 | 100 | #if defined( AES_192 ) || defined( AES_VAR) 101 | AES_RETURN aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]); 102 | #endif 103 | 104 | #if defined( AES_256 ) || defined( AES_VAR) 105 | AES_RETURN aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]); 106 | #endif 107 | 108 | #if defined( AES_VAR ) 109 | AES_RETURN aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]); 110 | #endif 111 | 112 | AES_RETURN aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]); 113 | 114 | #endif 115 | 116 | #if defined( AES_DECRYPT ) 117 | 118 | #if defined( AES_128 ) || defined( AES_VAR) 119 | AES_RETURN aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]); 120 | #endif 121 | 122 | #if defined( AES_192 ) || defined( AES_VAR) 123 | AES_RETURN aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]); 124 | #endif 125 | 126 | #if defined( AES_256 ) || defined( AES_VAR) 127 | AES_RETURN aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]); 128 | #endif 129 | 130 | #if defined( AES_VAR ) 131 | AES_RETURN aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]); 132 | #endif 133 | 134 | AES_RETURN aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]); 135 | 136 | #endif 137 | 138 | #if defined( AES_MODES ) 139 | 140 | /* Multiple calls to the following subroutines for multiple block */ 141 | /* ECB, CBC, CFB, OFB and CTR mode encryption can be used to handle */ 142 | /* long messages incremantally provided that the context AND the iv */ 143 | /* are preserved between all such calls. For the ECB and CBC modes */ 144 | /* each individual call within a series of incremental calls must */ 145 | /* process only full blocks (i.e. len must be a multiple of 16) but */ 146 | /* the CFB, OFB and CTR mode calls can handle multiple incremental */ 147 | /* calls of any length. Each mode is reset when a new AES key is */ 148 | /* set but ECB and CBC operations can be reset without setting a */ 149 | /* new key by setting a new IV value. To reset CFB, OFB and CTR */ 150 | /* without setting the key, aes_mode_reset() must be called and the */ 151 | /* IV must be set. NOTE: All these calls update the IV on exit so */ 152 | /* this has to be reset if a new operation with the same IV as the */ 153 | /* previous one is required (or decryption follows encryption with */ 154 | /* the same IV array). */ 155 | 156 | AES_RETURN aes_test_alignment_detection(unsigned int n); 157 | 158 | AES_RETURN aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf, 159 | int len, const aes_encrypt_ctx cx[1]); 160 | 161 | AES_RETURN aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf, 162 | int len, const aes_decrypt_ctx cx[1]); 163 | 164 | AES_RETURN aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf, 165 | int len, unsigned char *iv, const aes_encrypt_ctx cx[1]); 166 | 167 | AES_RETURN aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf, 168 | int len, unsigned char *iv, const aes_decrypt_ctx cx[1]); 169 | 170 | AES_RETURN aes_mode_reset(aes_encrypt_ctx cx[1]); 171 | 172 | AES_RETURN aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf, 173 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 174 | 175 | AES_RETURN aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf, 176 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 177 | 178 | #define aes_ofb_encrypt aes_ofb_crypt 179 | #define aes_ofb_decrypt aes_ofb_crypt 180 | 181 | AES_RETURN aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf, 182 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 183 | 184 | typedef void cbuf_inc(unsigned char *cbuf); 185 | 186 | #define aes_ctr_encrypt aes_ctr_crypt 187 | #define aes_ctr_decrypt aes_ctr_crypt 188 | 189 | AES_RETURN aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf, 190 | int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]); 191 | 192 | #endif 193 | 194 | #if defined(__cplusplus) 195 | } 196 | #endif 197 | 198 | #endif 199 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/aestab.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This file contains the code for declaring the tables needed to implement 21 | AES. The file aesopt.h is assumed to be included before this header file. 22 | If there are no global variables, the definitions here can be used to put 23 | the AES tables in a structure so that a pointer can then be added to the 24 | AES context to pass them to the AES routines that need them. If this 25 | facility is used, the calling program has to ensure that this pointer is 26 | managed appropriately. In particular, the value of the t_dec(in,it) item 27 | in the table structure must be set to zero in order to ensure that the 28 | tables are initialised. In practice the three code sequences in aeskey.c 29 | that control the calls to aes_init() and the aes_init() routine itself will 30 | have to be changed for a specific implementation. If global variables are 31 | available it will generally be preferable to use them with the precomputed 32 | FIXED_TABLES option that uses static global tables. 33 | 34 | The following defines can be used to control the way the tables 35 | are defined, initialised and used in embedded environments that 36 | require special features for these purposes 37 | 38 | the 't_dec' construction is used to declare fixed table arrays 39 | the 't_set' construction is used to set fixed table values 40 | the 't_use' construction is used to access fixed table values 41 | 42 | 256 byte tables: 43 | 44 | t_xxx(s,box) => forward S box 45 | t_xxx(i,box) => inverse S box 46 | 47 | 256 32-bit word OR 4 x 256 32-bit word tables: 48 | 49 | t_xxx(f,n) => forward normal round 50 | t_xxx(f,l) => forward last round 51 | t_xxx(i,n) => inverse normal round 52 | t_xxx(i,l) => inverse last round 53 | t_xxx(l,s) => key schedule table 54 | t_xxx(i,m) => key schedule table 55 | 56 | Other variables and tables: 57 | 58 | t_xxx(r,c) => the rcon table 59 | */ 60 | 61 | #if !defined( _AESTAB_H ) 62 | #define _AESTAB_H 63 | 64 | #if defined(__cplusplus) 65 | extern "C" { 66 | #endif 67 | 68 | #define t_dec(m,n) t_##m##n 69 | #define t_set(m,n) t_##m##n 70 | #define t_use(m,n) t_##m##n 71 | 72 | #if defined(FIXED_TABLES) 73 | # if !defined( __GNUC__ ) && (defined( __MSDOS__ ) || defined( __WIN16__ )) 74 | /* make tables far data to avoid using too much DGROUP space (PG) */ 75 | # define CONST const far 76 | # else 77 | # define CONST const 78 | # endif 79 | #else 80 | # define CONST 81 | #endif 82 | 83 | #if defined(DO_TABLES) 84 | # define EXTERN 85 | #else 86 | # define EXTERN extern 87 | #endif 88 | 89 | #if defined(_MSC_VER) && defined(TABLE_ALIGN) 90 | #define ALIGN __declspec(align(TABLE_ALIGN)) 91 | #else 92 | #define ALIGN 93 | #endif 94 | 95 | #if defined( __WATCOMC__ ) && ( __WATCOMC__ >= 1100 ) 96 | # define XP_DIR __cdecl 97 | #else 98 | # define XP_DIR 99 | #endif 100 | 101 | #if defined(DO_TABLES) && defined(FIXED_TABLES) 102 | #define d_1(t,n,b,e) EXTERN ALIGN CONST XP_DIR t n[256] = b(e) 103 | #define d_4(t,n,b,e,f,g,h) EXTERN ALIGN CONST XP_DIR t n[4][256] = { b(e), b(f), b(g), b(h) } 104 | EXTERN ALIGN CONST uint_32t t_dec(r,c)[RC_LENGTH] = rc_data(w0); 105 | #else 106 | #define d_1(t,n,b,e) EXTERN ALIGN CONST XP_DIR t n[256] 107 | #define d_4(t,n,b,e,f,g,h) EXTERN ALIGN CONST XP_DIR t n[4][256] 108 | EXTERN ALIGN CONST uint_32t t_dec(r,c)[RC_LENGTH]; 109 | #endif 110 | 111 | #if defined( SBX_SET ) 112 | d_1(uint_8t, t_dec(s,box), sb_data, h0); 113 | #endif 114 | #if defined( ISB_SET ) 115 | d_1(uint_8t, t_dec(i,box), isb_data, h0); 116 | #endif 117 | 118 | #if defined( FT1_SET ) 119 | d_1(uint_32t, t_dec(f,n), sb_data, u0); 120 | #endif 121 | #if defined( FT4_SET ) 122 | d_4(uint_32t, t_dec(f,n), sb_data, u0, u1, u2, u3); 123 | #endif 124 | 125 | #if defined( FL1_SET ) 126 | d_1(uint_32t, t_dec(f,l), sb_data, w0); 127 | #endif 128 | #if defined( FL4_SET ) 129 | d_4(uint_32t, t_dec(f,l), sb_data, w0, w1, w2, w3); 130 | #endif 131 | 132 | #if defined( IT1_SET ) 133 | d_1(uint_32t, t_dec(i,n), isb_data, v0); 134 | #endif 135 | #if defined( IT4_SET ) 136 | d_4(uint_32t, t_dec(i,n), isb_data, v0, v1, v2, v3); 137 | #endif 138 | 139 | #if defined( IL1_SET ) 140 | d_1(uint_32t, t_dec(i,l), isb_data, w0); 141 | #endif 142 | #if defined( IL4_SET ) 143 | d_4(uint_32t, t_dec(i,l), isb_data, w0, w1, w2, w3); 144 | #endif 145 | 146 | #if defined( LS1_SET ) 147 | #if defined( FL1_SET ) 148 | #undef LS1_SET 149 | #else 150 | d_1(uint_32t, t_dec(l,s), sb_data, w0); 151 | #endif 152 | #endif 153 | 154 | #if defined( LS4_SET ) 155 | #if defined( FL4_SET ) 156 | #undef LS4_SET 157 | #else 158 | d_4(uint_32t, t_dec(l,s), sb_data, w0, w1, w2, w3); 159 | #endif 160 | #endif 161 | 162 | #if defined( IM1_SET ) 163 | d_1(uint_32t, t_dec(i,m), mm_data, v0); 164 | #endif 165 | #if defined( IM4_SET ) 166 | d_4(uint_32t, t_dec(i,m), mm_data, v0, v1, v2, v3); 167 | #endif 168 | 169 | #if defined(__cplusplus) 170 | } 171 | #endif 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/brg_endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | */ 20 | 21 | #ifndef _BRG_ENDIAN_H 22 | #define _BRG_ENDIAN_H 23 | 24 | #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ 25 | #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ 26 | 27 | /* Include files where endian defines and byteswap functions may reside */ 28 | #if defined( __sun ) 29 | # include 30 | #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ ) 31 | # include 32 | #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \ 33 | defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ ) 34 | # include 35 | #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ ) 36 | # if !defined( __MINGW32__ ) && !defined( _AIX ) 37 | # include 38 | # if !defined( __BEOS__ ) 39 | # include 40 | # endif 41 | # endif 42 | #endif 43 | 44 | /* Now attempt to set the define for platform byte order using any */ 45 | /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */ 46 | /* seem to encompass most endian symbol definitions */ 47 | 48 | #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN ) 49 | # if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN 50 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 51 | # elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN 52 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 53 | # endif 54 | #elif defined( BIG_ENDIAN ) 55 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 56 | #elif defined( LITTLE_ENDIAN ) 57 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 58 | #endif 59 | 60 | #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN ) 61 | # if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN 62 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 63 | # elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN 64 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 65 | # endif 66 | #elif defined( _BIG_ENDIAN ) 67 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 68 | #elif defined( _LITTLE_ENDIAN ) 69 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 70 | #endif 71 | 72 | #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN ) 73 | # if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN 74 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 75 | # elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN 76 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 77 | # endif 78 | #elif defined( __BIG_ENDIAN ) 79 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 80 | #elif defined( __LITTLE_ENDIAN ) 81 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 82 | #endif 83 | 84 | #if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ ) 85 | # if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__ 86 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 87 | # elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__ 88 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 89 | # endif 90 | #elif defined( __BIG_ENDIAN__ ) 91 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 92 | #elif defined( __LITTLE_ENDIAN__ ) 93 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 94 | #endif 95 | 96 | /* if the platform byte order could not be determined, then try to */ 97 | /* set this define using common machine defines */ 98 | #if !defined(PLATFORM_BYTE_ORDER) 99 | 100 | #if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ 101 | defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \ 102 | defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \ 103 | defined( vax ) || defined( vms ) || defined( VMS ) || \ 104 | defined( __VMS ) || defined( _M_X64 ) 105 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 106 | 107 | #elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ 108 | defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \ 109 | defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \ 110 | defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \ 111 | defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \ 112 | defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \ 113 | defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX ) 114 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 115 | 116 | #elif 0 /* **** EDIT HERE IF NECESSARY **** */ 117 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 118 | #elif 0 /* **** EDIT HERE IF NECESSARY **** */ 119 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 120 | #else 121 | # error Please edit lines 126 or 128 in brg_endian.h to set the platform byte order 122 | #endif 123 | 124 | #endif 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/brg_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | The unsigned integer types defined here are of the form uint_t where 21 | is the length of the type; for example, the unsigned 32-bit type is 22 | 'uint_32t'. These are NOT the same as the 'C99 integer types' that are 23 | defined in the inttypes.h and stdint.h headers since attempts to use these 24 | types have shown that support for them is still highly variable. However, 25 | since the latter are of the form uint_t, a regular expression search 26 | and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t') 27 | can be used to convert the types used here to the C99 standard types. 28 | */ 29 | 30 | #ifndef _BRG_TYPES_H 31 | #define _BRG_TYPES_H 32 | 33 | #if defined(__cplusplus) 34 | extern "C" { 35 | #endif 36 | 37 | #include 38 | 39 | #if defined( _MSC_VER ) && ( _MSC_VER >= 1300 ) 40 | # include 41 | # define ptrint_t intptr_t 42 | #elif defined( __ECOS__ ) 43 | # define intptr_t unsigned int 44 | # define ptrint_t intptr_t 45 | #elif defined( __GNUC__ ) && ( __GNUC__ >= 3 ) 46 | # include 47 | # define ptrint_t intptr_t 48 | #else 49 | # define ptrint_t int 50 | #endif 51 | 52 | #ifndef BRG_UI8 53 | # define BRG_UI8 54 | # if UCHAR_MAX == 255u 55 | typedef unsigned char uint_8t; 56 | # else 57 | # error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h 58 | # endif 59 | #endif 60 | 61 | #ifndef BRG_UI16 62 | # define BRG_UI16 63 | # if USHRT_MAX == 65535u 64 | typedef unsigned short uint_16t; 65 | # else 66 | # error Please define uint_16t as a 16-bit unsigned short type in brg_types.h 67 | # endif 68 | #endif 69 | 70 | #ifndef BRG_UI32 71 | # define BRG_UI32 72 | # if UINT_MAX == 4294967295u 73 | # define li_32(h) 0x##h##u 74 | typedef unsigned int uint_32t; 75 | # elif ULONG_MAX == 4294967295u 76 | # define li_32(h) 0x##h##ul 77 | typedef unsigned long uint_32t; 78 | # elif defined( _CRAY ) 79 | # error This code needs 32-bit data types, which Cray machines do not provide 80 | # else 81 | # error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h 82 | # endif 83 | #endif 84 | 85 | #ifndef BRG_UI64 86 | # if defined( __BORLANDC__ ) && !defined( __MSDOS__ ) 87 | # define BRG_UI64 88 | # define li_64(h) 0x##h##ui64 89 | typedef unsigned __int64 uint_64t; 90 | # elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */ 91 | # define BRG_UI64 92 | # define li_64(h) 0x##h##ui64 93 | typedef unsigned __int64 uint_64t; 94 | # elif defined( __sun ) && defined( ULONG_MAX ) && ULONG_MAX == 0xfffffffful 95 | # define BRG_UI64 96 | # define li_64(h) 0x##h##ull 97 | typedef unsigned long long uint_64t; 98 | # elif defined( __MVS__ ) 99 | # define BRG_UI64 100 | # define li_64(h) 0x##h##ull 101 | typedef unsigned int long long uint_64t; 102 | # elif defined( UINT_MAX ) && UINT_MAX > 4294967295u 103 | # if UINT_MAX == 18446744073709551615u 104 | # define BRG_UI64 105 | # define li_64(h) 0x##h##u 106 | typedef unsigned int uint_64t; 107 | # endif 108 | # elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u 109 | # if ULONG_MAX == 18446744073709551615ul 110 | # define BRG_UI64 111 | # define li_64(h) 0x##h##ul 112 | typedef unsigned long uint_64t; 113 | # endif 114 | # elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u 115 | # if ULLONG_MAX == 18446744073709551615ull 116 | # define BRG_UI64 117 | # define li_64(h) 0x##h##ull 118 | typedef unsigned long long uint_64t; 119 | # endif 120 | # elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u 121 | # if ULONG_LONG_MAX == 18446744073709551615ull 122 | # define BRG_UI64 123 | # define li_64(h) 0x##h##ull 124 | typedef unsigned long long uint_64t; 125 | # endif 126 | # endif 127 | #endif 128 | 129 | #if !defined( BRG_UI64 ) 130 | # if defined( NEED_UINT_64T ) 131 | # error Please define uint_64t as an unsigned 64 bit type in brg_types.h 132 | # endif 133 | #endif 134 | 135 | #ifndef RETURN_VALUES 136 | # define RETURN_VALUES 137 | # if defined( DLL_EXPORT ) 138 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 139 | # define VOID_RETURN __declspec( dllexport ) void __stdcall 140 | # define INT_RETURN __declspec( dllexport ) int __stdcall 141 | # elif defined( __GNUC__ ) 142 | # define VOID_RETURN __declspec( __dllexport__ ) void 143 | # define INT_RETURN __declspec( __dllexport__ ) int 144 | # else 145 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 146 | # endif 147 | # elif defined( DLL_IMPORT ) 148 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 149 | # define VOID_RETURN __declspec( dllimport ) void __stdcall 150 | # define INT_RETURN __declspec( dllimport ) int __stdcall 151 | # elif defined( __GNUC__ ) 152 | # define VOID_RETURN __declspec( __dllimport__ ) void 153 | # define INT_RETURN __declspec( __dllimport__ ) int 154 | # else 155 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 156 | # endif 157 | # elif defined( __WATCOMC__ ) 158 | # define VOID_RETURN void __cdecl 159 | # define INT_RETURN int __cdecl 160 | # else 161 | # define VOID_RETURN void 162 | # define INT_RETURN int 163 | # endif 164 | #endif 165 | 166 | /* These defines are used to detect and set the memory alignment of pointers. 167 | Note that offsets are in bytes. 168 | 169 | ALIGN_OFFSET(x,n) return the positive or zero offset of 170 | the memory addressed by the pointer 'x' 171 | from an address that is aligned on an 172 | 'n' byte boundary ('n' is a power of 2) 173 | 174 | ALIGN_FLOOR(x,n) return a pointer that points to memory 175 | that is aligned on an 'n' byte boundary 176 | and is not higher than the memory address 177 | pointed to by 'x' ('n' is a power of 2) 178 | 179 | ALIGN_CEIL(x,n) return a pointer that points to memory 180 | that is aligned on an 'n' byte boundary 181 | and is not lower than the memory address 182 | pointed to by 'x' ('n' is a power of 2) 183 | */ 184 | 185 | #define ALIGN_OFFSET(x,n) (((ptrint_t)(x)) & ((n) - 1)) 186 | #define ALIGN_FLOOR(x,n) ((uint_8t*)(x) - ( ((ptrint_t)(x)) & ((n) - 1))) 187 | #define ALIGN_CEIL(x,n) ((uint_8t*)(x) + (-((ptrint_t)(x)) & ((n) - 1))) 188 | 189 | /* These defines are used to declare buffers in a way that allows 190 | faster operations on longer variables to be used. In all these 191 | defines 'size' must be a power of 2 and >= 8. NOTE that the 192 | buffer size is in bytes but the type length is in bits 193 | 194 | UNIT_TYPEDEF(x,size) declares a variable 'x' of length 195 | 'size' bits 196 | 197 | BUFR_TYPEDEF(x,size,bsize) declares a buffer 'x' of length 'bsize' 198 | bytes defined as an array of variables 199 | each of 'size' bits (bsize must be a 200 | multiple of size / 8) 201 | 202 | UNIT_CAST(x,size) casts a variable to a type of 203 | length 'size' bits 204 | 205 | UPTR_CAST(x,size) casts a pointer to a pointer to a 206 | varaiable of length 'size' bits 207 | */ 208 | 209 | #define UI_TYPE(size) uint_##size##t 210 | #define UNIT_TYPEDEF(x,size) typedef UI_TYPE(size) x 211 | #define BUFR_TYPEDEF(x,size,bsize) typedef UI_TYPE(size) x[bsize / (size >> 3)] 212 | #define UNIT_CAST(x,size) ((UI_TYPE(size) )(x)) 213 | #define UPTR_CAST(x,size) ((UI_TYPE(size)*)(x)) 214 | 215 | #if defined(__cplusplus) 216 | } 217 | #endif 218 | 219 | #endif 220 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/entropy.c: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | #include 3 | #else 4 | #include 5 | #include 6 | #include 7 | #endif 8 | 9 | #if defined(__cplusplus) 10 | extern "C" 11 | { 12 | #endif 13 | 14 | #ifdef _WIN32 15 | int entropy_fun(unsigned char buf[], unsigned int len) 16 | { 17 | HCRYPTPROV provider; 18 | unsigned __int64 pentium_tsc[1]; 19 | unsigned int i; 20 | int result = 0; 21 | 22 | 23 | if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) 24 | { 25 | result = CryptGenRandom(provider, len, buf); 26 | CryptReleaseContext(provider, 0); 27 | if (result) 28 | return len; 29 | } 30 | 31 | QueryPerformanceCounter((LARGE_INTEGER *)pentium_tsc); 32 | 33 | for(i = 0; i < 8 && i < len; ++i) 34 | buf[i] = ((unsigned char*)pentium_tsc)[i]; 35 | 36 | return i; 37 | } 38 | #else 39 | int entropy_fun(unsigned char buf[], unsigned int len) 40 | { 41 | int frand = open("/dev/random", O_RDONLY); 42 | int rlen = 0; 43 | if (frand != -1) 44 | { 45 | rlen = (int)read(frand, buf, len); 46 | close(frand); 47 | } 48 | return rlen; 49 | } 50 | #endif 51 | 52 | #if defined(__cplusplus) 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/entropy.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENTROPY_FUN_H 3 | #define _ENTROPY_FUN_H 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | int entropy_fun(unsigned char buf[], unsigned int len); 11 | 12 | #if defined(__cplusplus) 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/fileenc.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | ------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file implements password based file encryption and authentication 34 | using AES in CTR mode, HMAC-SHA1 authentication and RFC2898 password 35 | based key derivation. 36 | 37 | */ 38 | 39 | #include 40 | 41 | #include "fileenc.h" 42 | 43 | #if defined(__cplusplus) 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /* subroutine for data encryption/decryption */ 49 | /* this could be speeded up a lot by aligning */ 50 | /* buffers and using 32 bit operations */ 51 | 52 | static void encr_data(unsigned char data[], unsigned long d_len, fcrypt_ctx cx[1]) 53 | { 54 | unsigned long i = 0, pos = cx->encr_pos; 55 | 56 | while (i < d_len) { 57 | if (pos == AES_BLOCK_SIZE) { 58 | unsigned int j = 0; 59 | /* increment encryption nonce */ 60 | while (j < 8 && !++cx->nonce[j]) 61 | ++j; 62 | /* encrypt the nonce to form next xor buffer */ 63 | aes_encrypt(cx->nonce, cx->encr_bfr, cx->encr_ctx); 64 | pos = 0; 65 | } 66 | 67 | data[i++] ^= cx->encr_bfr[pos++]; 68 | } 69 | 70 | cx->encr_pos = (unsigned int)pos; 71 | } 72 | 73 | int fcrypt_init( 74 | int mode, /* the mode to be used (input) */ 75 | const unsigned char pwd[], /* the user specified password (input) */ 76 | unsigned int pwd_len, /* the length of the password (input) */ 77 | const unsigned char salt[], /* the salt (input) */ 78 | #ifdef PASSWORD_VERIFIER 79 | unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */ 80 | #endif 81 | fcrypt_ctx cx[1]) /* the file encryption context (output) */ 82 | { 83 | unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH]; 84 | 85 | if (pwd_len > MAX_PWD_LENGTH) 86 | return PASSWORD_TOO_LONG; 87 | 88 | if (mode < 1 || mode > 3) 89 | return BAD_MODE; 90 | 91 | cx->mode = mode; 92 | cx->pwd_len = pwd_len; 93 | 94 | /* derive the encryption and authentication keys and the password verifier */ 95 | derive_key(pwd, pwd_len, salt, SALT_LENGTH(mode), KEYING_ITERATIONS, 96 | kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH); 97 | 98 | /* initialise the encryption nonce and buffer pos */ 99 | cx->encr_pos = AES_BLOCK_SIZE; 100 | /* if we need a random component in the encryption */ 101 | /* nonce, this is where it would have to be set */ 102 | memset(cx->nonce, 0, AES_BLOCK_SIZE * sizeof(unsigned char)); 103 | 104 | /* initialise for encryption using key 1 */ 105 | aes_encrypt_key(kbuf, KEY_LENGTH(mode), cx->encr_ctx); 106 | 107 | /* initialise for authentication using key 2 */ 108 | hmac_sha_begin(cx->auth_ctx); 109 | hmac_sha_key(kbuf + KEY_LENGTH(mode), KEY_LENGTH(mode), cx->auth_ctx); 110 | 111 | #ifdef PASSWORD_VERIFIER 112 | memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH); 113 | #endif 114 | 115 | return GOOD_RETURN; 116 | } 117 | 118 | /* perform 'in place' encryption and authentication */ 119 | 120 | void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]) 121 | { 122 | encr_data(data, data_len, cx); 123 | hmac_sha_data(data, data_len, cx->auth_ctx); 124 | } 125 | 126 | /* perform 'in place' authentication and decryption */ 127 | 128 | void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]) 129 | { 130 | hmac_sha_data(data, data_len, cx->auth_ctx); 131 | encr_data(data, data_len, cx); 132 | } 133 | 134 | /* close encryption/decryption and return the MAC value */ 135 | 136 | int fcrypt_end(unsigned char mac[], fcrypt_ctx cx[1]) 137 | { 138 | hmac_sha_end(mac, MAC_LENGTH(cx->mode), cx->auth_ctx); 139 | return MAC_LENGTH(cx->mode); /* return MAC length in bytes */ 140 | } 141 | 142 | #if defined(__cplusplus) 143 | } 144 | #endif 145 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/fileenc.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file contains the header file for fileenc.c, which implements password 34 | based file encryption and authentication using AES in CTR mode, HMAC-SHA1 35 | authentication and RFC2898 password based key derivation. 36 | */ 37 | 38 | #ifndef _FENC_H 39 | #define _FENC_H 40 | 41 | #include "aes.h" 42 | #include "hmac.h" 43 | #include "pwd2key.h" 44 | 45 | #define PASSWORD_VERIFIER 46 | 47 | #define MAX_KEY_LENGTH 32 48 | #define MAX_PWD_LENGTH 128 49 | #define MAX_SALT_LENGTH 16 50 | #define KEYING_ITERATIONS 1000 51 | 52 | #ifdef PASSWORD_VERIFIER 53 | #define PWD_VER_LENGTH 2 54 | #else 55 | #define PWD_VER_LENGTH 0 56 | #endif 57 | 58 | #define GOOD_RETURN 0 59 | #define PASSWORD_TOO_LONG -100 60 | #define BAD_MODE -101 61 | 62 | /* 63 | Field lengths (in bytes) versus File Encryption Mode (0 < mode < 4) 64 | 65 | Mode Key Salt MAC Overhead 66 | 1 16 8 10 18 67 | 2 24 12 10 22 68 | 3 32 16 10 26 69 | 70 | The following macros assume that the mode value is correct. 71 | */ 72 | 73 | #define KEY_LENGTH(mode) (8 * (mode & 3) + 8) 74 | #define SALT_LENGTH(mode) (4 * (mode & 3) + 4) 75 | #define MAC_LENGTH(mode) (10) 76 | 77 | /* the context for file encryption */ 78 | 79 | #if defined(__cplusplus) 80 | extern "C" 81 | { 82 | #endif 83 | 84 | typedef struct 85 | { unsigned char nonce[AES_BLOCK_SIZE]; /* the CTR nonce */ 86 | unsigned char encr_bfr[AES_BLOCK_SIZE]; /* encrypt buffer */ 87 | aes_encrypt_ctx encr_ctx[1]; /* encryption context */ 88 | hmac_ctx auth_ctx[1]; /* authentication context */ 89 | unsigned int encr_pos; /* block position (enc) */ 90 | unsigned int pwd_len; /* password length */ 91 | unsigned int mode; /* File encryption mode */ 92 | } fcrypt_ctx; 93 | 94 | /* initialise file encryption or decryption */ 95 | 96 | int fcrypt_init( 97 | int mode, /* the mode to be used (input) */ 98 | const unsigned char pwd[], /* the user specified password (input) */ 99 | unsigned int pwd_len, /* the length of the password (input) */ 100 | const unsigned char salt[], /* the salt (input) */ 101 | #ifdef PASSWORD_VERIFIER 102 | unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */ 103 | #endif 104 | fcrypt_ctx cx[1]); /* the file encryption context (output) */ 105 | 106 | /* perform 'in place' encryption or decryption and authentication */ 107 | 108 | void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]); 109 | void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]); 110 | 111 | /* close encryption/decryption and return the MAC value */ 112 | /* the return value is the length of the MAC */ 113 | 114 | int fcrypt_end(unsigned char mac[], /* the MAC value (output) */ 115 | fcrypt_ctx cx[1]); /* the context (input) */ 116 | 117 | #if defined(__cplusplus) 118 | } 119 | #endif 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/hmac.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of HMAC, the FIPS standard keyed hash function 33 | */ 34 | 35 | #include "hmac.h" 36 | #include "brg_types.h" 37 | 38 | #if defined(__cplusplus) 39 | extern "C" 40 | { 41 | #endif 42 | 43 | /* initialise the HMAC context to zero */ 44 | void hmac_sha_begin(hmac_ctx cx[1]) 45 | { 46 | memset(cx, 0, sizeof(hmac_ctx)); 47 | } 48 | 49 | /* input the HMAC key (can be called multiple times) */ 50 | int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]) 51 | { 52 | if(cx->klen == HMAC_IN_DATA) /* error if further key input */ 53 | return HMAC_BAD_MODE; /* is attempted in data mode */ 54 | 55 | if(cx->klen + key_len > HASH_INPUT_SIZE) /* if the key has to be hashed */ 56 | { 57 | if(cx->klen <= HASH_INPUT_SIZE) /* if the hash has not yet been */ 58 | { /* started, initialise it and */ 59 | sha_begin(cx->ctx); /* hash stored key characters */ 60 | sha_hash(cx->key, cx->klen, cx->ctx); 61 | } 62 | 63 | sha_hash(key, key_len, cx->ctx); /* hash long key data into hash */ 64 | } 65 | else /* otherwise store key data */ 66 | memcpy(cx->key + cx->klen, key, key_len); 67 | 68 | cx->klen += key_len; /* update the key length count */ 69 | return HMAC_OK; 70 | } 71 | 72 | /* input the HMAC data (can be called multiple times) - */ 73 | /* note that this call terminates the key input phase */ 74 | void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]) 75 | { unsigned int i; 76 | 77 | if(cx->klen != HMAC_IN_DATA) /* if not yet in data phase */ 78 | { 79 | if(cx->klen > HASH_INPUT_SIZE) /* if key is being hashed */ 80 | { /* complete the hash and */ 81 | sha_end(cx->key, cx->ctx); /* store the result as the */ 82 | cx->klen = HASH_OUTPUT_SIZE; /* key and set new length */ 83 | } 84 | 85 | /* pad the key if necessary */ 86 | memset(cx->key + cx->klen, 0, HASH_INPUT_SIZE - cx->klen); 87 | 88 | /* xor ipad into key value */ 89 | for(i = 0; i < (HASH_INPUT_SIZE >> 2); ++i) 90 | ((uint_32t*)cx->key)[i] ^= 0x36363636; 91 | 92 | /* and start hash operation */ 93 | sha_begin(cx->ctx); 94 | sha_hash(cx->key, HASH_INPUT_SIZE, cx->ctx); 95 | 96 | /* mark as now in data mode */ 97 | cx->klen = HMAC_IN_DATA; 98 | } 99 | 100 | /* hash the data (if any) */ 101 | if(data_len) 102 | sha_hash(data, data_len, cx->ctx); 103 | } 104 | 105 | /* compute and output the MAC value */ 106 | void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]) 107 | { unsigned char dig[HASH_OUTPUT_SIZE]; 108 | unsigned int i; 109 | 110 | /* if no data has been entered perform a null data phase */ 111 | if(cx->klen != HMAC_IN_DATA) 112 | hmac_sha_data((const unsigned char*)0, 0, cx); 113 | 114 | sha_end(dig, cx->ctx); /* complete the inner hash */ 115 | 116 | /* set outer key value using opad and removing ipad */ 117 | for(i = 0; i < (HASH_INPUT_SIZE >> 2); ++i) 118 | ((uint_32t*)cx->key)[i] ^= 0x36363636 ^ 0x5c5c5c5c; 119 | 120 | /* perform the outer hash operation */ 121 | sha_begin(cx->ctx); 122 | sha_hash(cx->key, HASH_INPUT_SIZE, cx->ctx); 123 | sha_hash(dig, HASH_OUTPUT_SIZE, cx->ctx); 124 | sha_end(dig, cx->ctx); 125 | 126 | /* output the hash value */ 127 | for(i = 0; i < mac_len; ++i) 128 | mac[i] = dig[i]; 129 | } 130 | 131 | /* 'do it all in one go' subroutine */ 132 | void hmac_sha(const unsigned char key[], unsigned long key_len, 133 | const unsigned char data[], unsigned long data_len, 134 | unsigned char mac[], unsigned long mac_len) 135 | { hmac_ctx cx[1]; 136 | 137 | hmac_sha_begin(cx); 138 | hmac_sha_key(key, key_len, cx); 139 | hmac_sha_data(data, data_len, cx); 140 | hmac_sha_end(mac, mac_len, cx); 141 | } 142 | 143 | #if defined(__cplusplus) 144 | } 145 | #endif 146 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/hmac.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of HMAC, the FIPS standard keyed hash function 33 | */ 34 | 35 | #ifndef _HMAC_H 36 | #define _HMAC_H 37 | 38 | #include 39 | 40 | #if defined(__cplusplus) 41 | extern "C" 42 | { 43 | #endif 44 | 45 | #define USE_SHA1 46 | 47 | #if !defined(USE_SHA1) && !defined(USE_SHA256) 48 | #error define USE_SHA1 or USE_SHA256 to set the HMAC hash algorithm 49 | #endif 50 | 51 | #ifdef USE_SHA1 52 | 53 | #include "sha1.h" 54 | 55 | #define HASH_INPUT_SIZE SHA1_BLOCK_SIZE 56 | #define HASH_OUTPUT_SIZE SHA1_DIGEST_SIZE 57 | #define sha_ctx sha1_ctx 58 | #define sha_begin sha1_begin 59 | #define sha_hash sha1_hash 60 | #define sha_end sha1_end 61 | 62 | #endif 63 | 64 | #ifdef USE_SHA256 65 | 66 | #include "sha2.h" 67 | 68 | #define HASH_INPUT_SIZE SHA256_BLOCK_SIZE 69 | #define HASH_OUTPUT_SIZE SHA256_DIGEST_SIZE 70 | #define sha_ctx sha256_ctx 71 | #define sha_begin sha256_begin 72 | #define sha_hash sha256_hash 73 | #define sha_end sha256_end 74 | 75 | #endif 76 | 77 | #define HMAC_OK 0 78 | #define HMAC_BAD_MODE -1 79 | #define HMAC_IN_DATA 0xffffffff 80 | 81 | typedef struct 82 | { unsigned char key[HASH_INPUT_SIZE]; 83 | sha_ctx ctx[1]; 84 | unsigned long klen; 85 | } hmac_ctx; 86 | 87 | void hmac_sha_begin(hmac_ctx cx[1]); 88 | 89 | int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]); 90 | 91 | void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]); 92 | 93 | void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]); 94 | 95 | void hmac_sha(const unsigned char key[], unsigned long key_len, 96 | const unsigned char data[], unsigned long data_len, 97 | unsigned char mac[], unsigned long mac_len); 98 | 99 | #if defined(__cplusplus) 100 | } 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/prng.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file implements a random data pool based on the use of an external 34 | entropy function. It is based on the ideas advocated by Peter Gutmann in 35 | his work on pseudo random sequence generators. It is not a 'paranoid' 36 | random sequence generator and no attempt is made to protect the pool 37 | from prying eyes either by memory locking or by techniques to obscure 38 | its location in memory. 39 | */ 40 | 41 | #include 42 | #include "prng.h" 43 | 44 | #if defined(__cplusplus) 45 | extern "C" 46 | { 47 | #endif 48 | 49 | /* mix a random data pool using the SHA1 compression function (as */ 50 | /* suggested by Peter Gutmann in his paper on random pools) */ 51 | 52 | static void prng_mix(unsigned char buf[]) 53 | { unsigned int i, len; 54 | sha1_ctx ctx[1]; 55 | 56 | /*lint -e{663} unusual array to pointer conversion */ 57 | for(i = 0; i < PRNG_POOL_SIZE; i += SHA1_DIGEST_SIZE) 58 | { 59 | /* copy digest size pool block into SHA1 hash block */ 60 | memcpy(ctx->hash, buf + (i ? i : PRNG_POOL_SIZE) 61 | - SHA1_DIGEST_SIZE, SHA1_DIGEST_SIZE); 62 | 63 | /* copy data from pool into the SHA1 data buffer */ 64 | len = PRNG_POOL_SIZE - i; 65 | memcpy(ctx->wbuf, buf + i, (len > SHA1_BLOCK_SIZE ? SHA1_BLOCK_SIZE : len)); 66 | 67 | if(len < SHA1_BLOCK_SIZE) 68 | memcpy(((char*)ctx->wbuf) + len, buf, SHA1_BLOCK_SIZE - len); 69 | 70 | /* compress using the SHA1 compression function */ 71 | sha1_compile(ctx); 72 | 73 | /* put digest size block back into the random pool */ 74 | memcpy(buf + i, ctx->hash, SHA1_DIGEST_SIZE); 75 | } 76 | } 77 | 78 | /* refresh the output buffer and update the random pool by adding */ 79 | /* entropy and remixing */ 80 | 81 | static void update_pool(prng_ctx ctx[1]) 82 | { unsigned int i = 0; 83 | 84 | /* transfer random pool data to the output buffer */ 85 | memcpy(ctx->obuf, ctx->rbuf, PRNG_POOL_SIZE); 86 | 87 | /* enter entropy data into the pool */ 88 | while(i < PRNG_POOL_SIZE) 89 | i += ctx->entropy(ctx->rbuf + i, PRNG_POOL_SIZE - i); 90 | 91 | /* invert and xor the original pool data into the pool */ 92 | for(i = 0; i < PRNG_POOL_SIZE; ++i) 93 | ctx->rbuf[i] ^= ~ctx->obuf[i]; 94 | 95 | /* mix the pool and the output buffer */ 96 | prng_mix(ctx->rbuf); 97 | prng_mix(ctx->obuf); 98 | } 99 | 100 | void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]) 101 | { int i; 102 | 103 | /* clear the buffers and the counter in the context */ 104 | memset(ctx, 0, sizeof(prng_ctx)); 105 | 106 | /* set the pointer to the entropy collection function */ 107 | ctx->entropy = fun; 108 | 109 | /* initialise the random data pool */ 110 | update_pool(ctx); 111 | 112 | /* mix the pool a minimum number of times */ 113 | for(i = 0; i < PRNG_MIN_MIX; ++i) 114 | prng_mix(ctx->rbuf); 115 | 116 | /* update the pool to prime the pool output buffer */ 117 | update_pool(ctx); 118 | } 119 | 120 | /* provide random bytes from the random data pool */ 121 | 122 | void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]) 123 | { unsigned char *rp = data; 124 | unsigned int len, pos = ctx->pos; 125 | 126 | while(data_len) 127 | { 128 | /* transfer 'data_len' bytes (or the number of bytes remaining */ 129 | /* the pool output buffer if less) into the output */ 130 | len = (data_len < PRNG_POOL_SIZE - pos ? data_len : PRNG_POOL_SIZE - pos); 131 | memcpy(rp, ctx->obuf + pos, len); 132 | rp += len; /* update ouput buffer position pointer */ 133 | pos += len; /* update pool output buffer pointer */ 134 | data_len -= len; /* update the remaining data count */ 135 | 136 | /* refresh the random pool if necessary */ 137 | if(pos == PRNG_POOL_SIZE) 138 | { 139 | update_pool(ctx); pos = 0; 140 | } 141 | } 142 | 143 | ctx->pos = pos; 144 | } 145 | 146 | void prng_end(prng_ctx ctx[1]) 147 | { 148 | /* ensure the data in the context is destroyed */ 149 | memset(ctx, 0, sizeof(prng_ctx)); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/prng.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This is the header file for an implementation of a random data pool based on 34 | the use of an external entropy function (inspired by Peter Gutmann's work). 35 | */ 36 | 37 | #ifndef _PRNG_H 38 | #define _PRNG_H 39 | 40 | #include "sha1.h" 41 | 42 | #define PRNG_POOL_LEN 256 /* minimum random pool size */ 43 | #define PRNG_MIN_MIX 20 /* min initial pool mixing iterations */ 44 | 45 | /* ensure that pool length is a multiple of the SHA1 digest size */ 46 | 47 | #define PRNG_POOL_SIZE (SHA1_DIGEST_SIZE * (1 + (PRNG_POOL_LEN - 1) / SHA1_DIGEST_SIZE)) 48 | 49 | #if defined(__cplusplus) 50 | extern "C" 51 | { 52 | #endif 53 | 54 | /* A function for providing entropy is a parameter in the prng_init() */ 55 | /* call. This function has the following form and returns a maximum */ 56 | /* of 'len' bytes of pseudo random data in the buffer 'buf'. It can */ 57 | /* return less than 'len' bytes but will be repeatedly called for more */ 58 | /* data in this case. */ 59 | 60 | typedef int (*prng_entropy_fn)(unsigned char buf[], unsigned int len); 61 | 62 | typedef struct 63 | { unsigned char rbuf[PRNG_POOL_SIZE]; /* the random pool */ 64 | unsigned char obuf[PRNG_POOL_SIZE]; /* pool output buffer */ 65 | unsigned int pos; /* output buffer position */ 66 | prng_entropy_fn entropy; /* entropy function pointer */ 67 | } prng_ctx; 68 | 69 | /* initialise the random stream generator */ 70 | void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]); 71 | 72 | /* obtain random bytes from the generator */ 73 | void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]); 74 | 75 | /* close the random stream generator */ 76 | void prng_end(prng_ctx ctx[1]); 77 | 78 | #if defined(__cplusplus) 79 | } 80 | #endif 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/pwd2key.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of RFC2898, which specifies key derivation from 33 | a password and a salt value. 34 | */ 35 | 36 | #include 37 | #include "hmac.h" 38 | 39 | #if defined(__cplusplus) 40 | extern "C" 41 | { 42 | #endif 43 | 44 | void derive_key(const unsigned char pwd[], /* the PASSWORD */ 45 | unsigned int pwd_len, /* and its length */ 46 | const unsigned char salt[], /* the SALT and its */ 47 | unsigned int salt_len, /* length */ 48 | unsigned int iter, /* the number of iterations */ 49 | unsigned char key[], /* space for the output key */ 50 | unsigned int key_len)/* and its required length */ 51 | { 52 | unsigned int i, j, k, n_blk; 53 | unsigned char uu[HASH_OUTPUT_SIZE], ux[HASH_OUTPUT_SIZE]; 54 | hmac_ctx c1[1], c2[1], c3[1]; 55 | 56 | /* set HMAC context (c1) for password */ 57 | hmac_sha_begin(c1); 58 | hmac_sha_key(pwd, pwd_len, c1); 59 | 60 | /* set HMAC context (c2) for password and salt */ 61 | memcpy(c2, c1, sizeof(hmac_ctx)); 62 | hmac_sha_data(salt, salt_len, c2); 63 | 64 | /* find the number of SHA blocks in the key */ 65 | n_blk = 1 + (key_len - 1) / HASH_OUTPUT_SIZE; 66 | 67 | for(i = 0; i < n_blk; ++i) /* for each block in key */ 68 | { 69 | /* ux[] holds the running xor value */ 70 | memset(ux, 0, HASH_OUTPUT_SIZE); 71 | 72 | /* set HMAC context (c3) for password and salt */ 73 | memcpy(c3, c2, sizeof(hmac_ctx)); 74 | 75 | /* enter additional data for 1st block into uu */ 76 | uu[0] = (unsigned char)((i + 1) >> 24); 77 | uu[1] = (unsigned char)((i + 1) >> 16); 78 | uu[2] = (unsigned char)((i + 1) >> 8); 79 | uu[3] = (unsigned char)(i + 1); 80 | 81 | /* this is the key mixing iteration */ 82 | for(j = 0, k = 4; j < iter; ++j) 83 | { 84 | /* add previous round data to HMAC */ 85 | hmac_sha_data(uu, k, c3); 86 | 87 | /* obtain HMAC for uu[] */ 88 | hmac_sha_end(uu, HASH_OUTPUT_SIZE, c3); 89 | 90 | /* xor into the running xor block */ 91 | for(k = 0; k < HASH_OUTPUT_SIZE; ++k) 92 | ux[k] ^= uu[k]; 93 | 94 | /* set HMAC context (c3) for password */ 95 | memcpy(c3, c1, sizeof(hmac_ctx)); 96 | } 97 | 98 | /* compile key blocks into the key output */ 99 | j = 0; k = i * HASH_OUTPUT_SIZE; 100 | while(j < HASH_OUTPUT_SIZE && k < key_len) 101 | key[k++] = ux[j++]; 102 | } 103 | } 104 | 105 | #ifdef TEST 106 | 107 | #include 108 | 109 | struct 110 | { unsigned int pwd_len; 111 | unsigned int salt_len; 112 | unsigned int it_count; 113 | unsigned char *pwd; 114 | unsigned char salt[32]; 115 | unsigned char key[32]; 116 | } tests[] = 117 | { 118 | { 8, 4, 5, (unsigned char*)"password", 119 | { 120 | 0x12, 0x34, 0x56, 0x78 121 | }, 122 | { 123 | 0x5c, 0x75, 0xce, 0xf0, 0x1a, 0x96, 0x0d, 0xf7, 124 | 0x4c, 0xb6, 0xb4, 0x9b, 0x9e, 0x38, 0xe6, 0xb5 125 | } 126 | }, 127 | { 8, 8, 5, (unsigned char*)"password", 128 | { 129 | 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12 130 | }, 131 | { 132 | 0xd1, 0xda, 0xa7, 0x86, 0x15, 0xf2, 0x87, 0xe6, 133 | 0xa1, 0xc8, 0xb1, 0x20, 0xd7, 0x06, 0x2a, 0x49 134 | } 135 | }, 136 | { 8, 21, 1, (unsigned char*)"password", 137 | { 138 | "ATHENA.MIT.EDUraeburn" 139 | }, 140 | { 141 | 0xcd, 0xed, 0xb5, 0x28, 0x1b, 0xb2, 0xf8, 0x01, 142 | 0x56, 0x5a, 0x11, 0x22, 0xb2, 0x56, 0x35, 0x15 143 | } 144 | }, 145 | { 8, 21, 2, (unsigned char*)"password", 146 | { 147 | "ATHENA.MIT.EDUraeburn" 148 | }, 149 | { 150 | 0x01, 0xdb, 0xee, 0x7f, 0x4a, 0x9e, 0x24, 0x3e, 151 | 0x98, 0x8b, 0x62, 0xc7, 0x3c, 0xda, 0x93, 0x5d 152 | } 153 | }, 154 | { 8, 21, 1200, (unsigned char*)"password", 155 | { 156 | "ATHENA.MIT.EDUraeburn" 157 | }, 158 | { 159 | 0x5c, 0x08, 0xeb, 0x61, 0xfd, 0xf7, 0x1e, 0x4e, 160 | 0x4e, 0xc3, 0xcf, 0x6b, 0xa1, 0xf5, 0x51, 0x2b 161 | } 162 | } 163 | }; 164 | 165 | int main() 166 | { unsigned int i, j, key_len = 256; 167 | unsigned char key[256]; 168 | 169 | printf("\nTest of RFC2898 Password Based Key Derivation"); 170 | for(i = 0; i < 5; ++i) 171 | { 172 | derive_key(tests[i].pwd, tests[i].pwd_len, tests[i].salt, 173 | tests[i].salt_len, tests[i].it_count, key, key_len); 174 | 175 | printf("\ntest %i: ", i + 1); 176 | printf("key %s", memcmp(tests[i].key, key, 16) ? "is bad" : "is good"); 177 | for(j = 0; j < key_len && j < 64; j += 4) 178 | { 179 | if(j % 16 == 0) 180 | printf("\n"); 181 | printf("0x%02x%02x%02x%02x ", key[j], key[j + 1], key[j + 2], key[j + 3]); 182 | } 183 | printf(j < key_len ? " ... \n" : "\n"); 184 | } 185 | printf("\n"); 186 | return 0; 187 | } 188 | 189 | #if defined(__cplusplus) 190 | } 191 | #endif 192 | 193 | #endif 194 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/pwd2key.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of RFC2898, which specifies key derivation from 33 | a password and a salt value. 34 | */ 35 | 36 | #ifndef PWD2KEY_H 37 | #define PWD2KEY_H 38 | 39 | #if defined(__cplusplus) 40 | extern "C" 41 | { 42 | #endif 43 | 44 | void derive_key( 45 | const unsigned char pwd[], /* the PASSWORD, and */ 46 | unsigned int pwd_len, /* its length */ 47 | const unsigned char salt[], /* the SALT and its */ 48 | unsigned int salt_len, /* length */ 49 | unsigned int iter, /* the number of iterations */ 50 | unsigned char key[], /* space for the output key */ 51 | unsigned int key_len); /* and its required length */ 52 | 53 | #if defined(__cplusplus) 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/sha1.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 01/08/2005 31 | 32 | This is a byte oriented version of SHA1 that operates on arrays of bytes 33 | stored in memory. 34 | */ 35 | 36 | #include /* for memcpy() etc. */ 37 | 38 | #include "sha1.h" 39 | #include "brg_endian.h" 40 | 41 | #if defined(__cplusplus) 42 | extern "C" 43 | { 44 | #endif 45 | 46 | #if defined( _MSC_VER ) && ( _MSC_VER > 800 ) 47 | #pragma intrinsic(memcpy) 48 | #endif 49 | 50 | #if 0 && defined(_MSC_VER) 51 | #define rotl32 _lrotl 52 | #define rotr32 _lrotr 53 | #else 54 | #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) 55 | #define rotr32(x,n) (((x) >> n) | ((x) << (32 - n))) 56 | #endif 57 | 58 | #if !defined(bswap_32) 59 | #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00)) 60 | #endif 61 | 62 | #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) 63 | #define SWAP_BYTES 64 | #else 65 | #undef SWAP_BYTES 66 | #endif 67 | 68 | #if defined(SWAP_BYTES) 69 | #define bsw_32(p,n) \ 70 | { int _i = (n); while(_i--) ((uint_32t*)p)[_i] = bswap_32(((uint_32t*)p)[_i]); } 71 | #else 72 | #define bsw_32(p,n) 73 | #endif 74 | 75 | #define SHA1_MASK (SHA1_BLOCK_SIZE - 1) 76 | 77 | #if 0 78 | 79 | #define ch(x,y,z) (((x) & (y)) ^ (~(x) & (z))) 80 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) 81 | #define maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) 82 | 83 | #else /* Discovered by Rich Schroeppel and Colin Plumb */ 84 | 85 | #define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) 86 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) 87 | #define maj(x,y,z) (((x) & (y)) | ((z) & ((x) ^ (y)))) 88 | 89 | #endif 90 | 91 | /* Compile 64 bytes of hash data into SHA1 context. Note */ 92 | /* that this routine assumes that the byte order in the */ 93 | /* ctx->wbuf[] at this point is in such an order that low */ 94 | /* address bytes in the ORIGINAL byte stream will go in */ 95 | /* this buffer to the high end of 32-bit words on BOTH big */ 96 | /* and little endian systems */ 97 | 98 | #ifdef ARRAY 99 | #define q(v,n) v[n] 100 | #else 101 | #define q(v,n) v##n 102 | #endif 103 | 104 | #define one_cycle(v,a,b,c,d,e,f,k,h) \ 105 | q(v,e) += rotr32(q(v,a),27) + \ 106 | f(q(v,b),q(v,c),q(v,d)) + k + h; \ 107 | q(v,b) = rotr32(q(v,b), 2) 108 | 109 | #define five_cycle(v,f,k,i) \ 110 | one_cycle(v, 0,1,2,3,4, f,k,hf(i )); \ 111 | one_cycle(v, 4,0,1,2,3, f,k,hf(i+1)); \ 112 | one_cycle(v, 3,4,0,1,2, f,k,hf(i+2)); \ 113 | one_cycle(v, 2,3,4,0,1, f,k,hf(i+3)); \ 114 | one_cycle(v, 1,2,3,4,0, f,k,hf(i+4)) 115 | 116 | VOID_RETURN sha1_compile(sha1_ctx ctx[1]) 117 | { uint_32t *w = ctx->wbuf; 118 | 119 | #ifdef ARRAY 120 | uint_32t v[5]; 121 | memcpy(v, ctx->hash, 5 * sizeof(uint_32t)); 122 | #else 123 | uint_32t v0, v1, v2, v3, v4; 124 | v0 = ctx->hash[0]; v1 = ctx->hash[1]; 125 | v2 = ctx->hash[2]; v3 = ctx->hash[3]; 126 | v4 = ctx->hash[4]; 127 | #endif 128 | 129 | #define hf(i) w[i] 130 | 131 | five_cycle(v, ch, 0x5a827999, 0); 132 | five_cycle(v, ch, 0x5a827999, 5); 133 | five_cycle(v, ch, 0x5a827999, 10); 134 | one_cycle(v,0,1,2,3,4, ch, 0x5a827999, hf(15)); \ 135 | 136 | #undef hf 137 | #define hf(i) (w[(i) & 15] = rotl32( \ 138 | w[((i) + 13) & 15] ^ w[((i) + 8) & 15] \ 139 | ^ w[((i) + 2) & 15] ^ w[(i) & 15], 1)) 140 | 141 | one_cycle(v,4,0,1,2,3, ch, 0x5a827999, hf(16)); 142 | one_cycle(v,3,4,0,1,2, ch, 0x5a827999, hf(17)); 143 | one_cycle(v,2,3,4,0,1, ch, 0x5a827999, hf(18)); 144 | one_cycle(v,1,2,3,4,0, ch, 0x5a827999, hf(19)); 145 | 146 | five_cycle(v, parity, 0x6ed9eba1, 20); 147 | five_cycle(v, parity, 0x6ed9eba1, 25); 148 | five_cycle(v, parity, 0x6ed9eba1, 30); 149 | five_cycle(v, parity, 0x6ed9eba1, 35); 150 | 151 | five_cycle(v, maj, 0x8f1bbcdc, 40); 152 | five_cycle(v, maj, 0x8f1bbcdc, 45); 153 | five_cycle(v, maj, 0x8f1bbcdc, 50); 154 | five_cycle(v, maj, 0x8f1bbcdc, 55); 155 | 156 | five_cycle(v, parity, 0xca62c1d6, 60); 157 | five_cycle(v, parity, 0xca62c1d6, 65); 158 | five_cycle(v, parity, 0xca62c1d6, 70); 159 | five_cycle(v, parity, 0xca62c1d6, 75); 160 | 161 | #ifdef ARRAY 162 | ctx->hash[0] += v[0]; ctx->hash[1] += v[1]; 163 | ctx->hash[2] += v[2]; ctx->hash[3] += v[3]; 164 | ctx->hash[4] += v[4]; 165 | #else 166 | ctx->hash[0] += v0; ctx->hash[1] += v1; 167 | ctx->hash[2] += v2; ctx->hash[3] += v3; 168 | ctx->hash[4] += v4; 169 | #endif 170 | } 171 | 172 | VOID_RETURN sha1_begin(sha1_ctx ctx[1]) 173 | { 174 | ctx->count[0] = ctx->count[1] = 0; 175 | ctx->hash[0] = 0x67452301; 176 | ctx->hash[1] = 0xefcdab89; 177 | ctx->hash[2] = 0x98badcfe; 178 | ctx->hash[3] = 0x10325476; 179 | ctx->hash[4] = 0xc3d2e1f0; 180 | } 181 | 182 | /* SHA1 hash data in an array of bytes into hash buffer and */ 183 | /* call the hash_compile function as required. */ 184 | 185 | VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]) 186 | { uint_32t pos = (uint_32t)(ctx->count[0] & SHA1_MASK), 187 | space = SHA1_BLOCK_SIZE - pos; 188 | const unsigned char *sp = data; 189 | 190 | if((ctx->count[0] += len) < len) 191 | ++(ctx->count[1]); 192 | 193 | while(len >= space) /* tranfer whole blocks if possible */ 194 | { 195 | memcpy(((unsigned char*)ctx->wbuf) + pos, sp, space); 196 | sp += space; len -= space; space = SHA1_BLOCK_SIZE; pos = 0; 197 | bsw_32(ctx->wbuf, SHA1_BLOCK_SIZE >> 2); 198 | sha1_compile(ctx); 199 | } 200 | 201 | memcpy(((unsigned char*)ctx->wbuf) + pos, sp, len); 202 | } 203 | 204 | /* SHA1 final padding and digest calculation */ 205 | 206 | VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]) 207 | { uint_32t i = (uint_32t)(ctx->count[0] & SHA1_MASK); 208 | 209 | /* put bytes in the buffer in an order in which references to */ 210 | /* 32-bit words will put bytes with lower addresses into the */ 211 | /* top of 32 bit words on BOTH big and little endian machines */ 212 | bsw_32(ctx->wbuf, (i + 3) >> 2); 213 | 214 | /* we now need to mask valid bytes and add the padding which is */ 215 | /* a single 1 bit and as many zero bits as necessary. Note that */ 216 | /* we can always add the first padding byte here because the */ 217 | /* buffer always has at least one empty slot */ 218 | ctx->wbuf[i >> 2] &= 0xffffff80 << 8 * (~i & 3); 219 | ctx->wbuf[i >> 2] |= 0x00000080 << 8 * (~i & 3); 220 | 221 | /* we need 9 or more empty positions, one for the padding byte */ 222 | /* (above) and eight for the length count. If there is not */ 223 | /* enough space, pad and empty the buffer */ 224 | if(i > SHA1_BLOCK_SIZE - 9) 225 | { 226 | if(i < 60) ctx->wbuf[15] = 0; 227 | sha1_compile(ctx); 228 | i = 0; 229 | } 230 | else /* compute a word index for the empty buffer positions */ 231 | i = (i >> 2) + 1; 232 | 233 | while(i < 14) /* and zero pad all but last two positions */ 234 | ctx->wbuf[i++] = 0; 235 | 236 | /* the following 32-bit length fields are assembled in the */ 237 | /* wrong byte order on little endian machines but this is */ 238 | /* corrected later since they are only ever used as 32-bit */ 239 | /* word values. */ 240 | ctx->wbuf[14] = (ctx->count[1] << 3) | (ctx->count[0] >> 29); 241 | ctx->wbuf[15] = ctx->count[0] << 3; 242 | sha1_compile(ctx); 243 | 244 | /* extract the hash value as bytes in case the hash buffer is */ 245 | /* misaligned for 32-bit words */ 246 | for(i = 0; i < SHA1_DIGEST_SIZE; ++i) 247 | hval[i] = (unsigned char)(ctx->hash[i >> 2] >> (8 * (~i & 3))); 248 | } 249 | 250 | VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len) 251 | { sha1_ctx cx[1]; 252 | 253 | sha1_begin(cx); sha1_hash(data, len, cx); sha1_end(hval, cx); 254 | } 255 | 256 | #if defined(__cplusplus) 257 | } 258 | #endif 259 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/aes/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 01/08/2005 31 | */ 32 | 33 | #ifndef _SHA1_H 34 | #define _SHA1_H 35 | 36 | #include 37 | #include "brg_types.h" 38 | 39 | #define SHA1_BLOCK_SIZE 64 40 | #define SHA1_DIGEST_SIZE 20 41 | 42 | #if defined(__cplusplus) 43 | extern "C" 44 | { 45 | #endif 46 | 47 | /* type to hold the SHA256 context */ 48 | 49 | typedef struct 50 | { uint_32t count[2]; 51 | uint_32t hash[5]; 52 | uint_32t wbuf[16]; 53 | } sha1_ctx; 54 | 55 | /* Note that these prototypes are the same for both bit and */ 56 | /* byte oriented implementations. However the length fields */ 57 | /* are in bytes or bits as appropriate for the version used */ 58 | /* and bit sequences are input as arrays of bytes in which */ 59 | /* bit sequences run from the most to the least significant */ 60 | /* end of each byte */ 61 | 62 | VOID_RETURN sha1_compile(sha1_ctx ctx[1]); 63 | 64 | VOID_RETURN sha1_begin(sha1_ctx ctx[1]); 65 | VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]); 66 | VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]); 67 | VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len); 68 | 69 | #if defined(__cplusplus) 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/minizip/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for traditional PKWARE encryption 2 | Version 1.01e, February 12th, 2005 3 | 4 | Copyright (C) 1998-2005 Gilles Vollant 5 | Modifications for Info-ZIP crypting 6 | Copyright (C) 2003 Terry Thorsen 7 | 8 | This code is a modified version of crypting code in Info-ZIP distribution 9 | 10 | Copyright (C) 1990-2000 Info-ZIP. All rights reserved. 11 | 12 | See the Info-ZIP LICENSE file version 2000-Apr-09 or later for terms of use 13 | which also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html 14 | 15 | The encryption/decryption parts of this source code (as opposed to the 16 | non-echoing password parts) were originally written in Europe. The 17 | whole source package can be freely distributed, including from the USA. 18 | (Prior to January 2000, re-export from the US was a violation of US law.) 19 | 20 | This encryption code is a direct transcription of the algorithm from 21 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 22 | file (appnote.txt) is distributed with the PKZIP program (even in the 23 | version without encryption capabilities). 24 | 25 | If you don't need crypting in your application, just define symbols 26 | NOCRYPT and NOUNCRYPT. 27 | */ 28 | 29 | #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 30 | 31 | /*********************************************************************** 32 | * Return the next byte in the pseudo-random sequence 33 | */ 34 | static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) 35 | { 36 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 37 | * unpredictable manner on 16-bit systems; not a problem 38 | * with any known compiler so far, though */ 39 | 40 | temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 41 | return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 42 | } 43 | 44 | /*********************************************************************** 45 | * Update the encryption keys with the next byte of plain text 46 | */ 47 | static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) 48 | { 49 | (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 50 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 51 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 52 | { 53 | register int keyshift = (int)((*(pkeys+1)) >> 24); 54 | (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 55 | } 56 | return c; 57 | } 58 | 59 | 60 | /*********************************************************************** 61 | * Initialize the encryption keys and the random header according to 62 | * the given password. 63 | */ 64 | static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) 65 | { 66 | *(pkeys+0) = 305419896L; 67 | *(pkeys+1) = 591751049L; 68 | *(pkeys+2) = 878082192L; 69 | while (*passwd != 0) { 70 | update_keys(pkeys,pcrc_32_tab,(int)*passwd); 71 | passwd++; 72 | } 73 | } 74 | 75 | #define zdecode(pkeys,pcrc_32_tab,c) \ 76 | (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 77 | 78 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 79 | (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 80 | 81 | #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 82 | 83 | #define RAND_HEAD_LEN 12 84 | /* "last resort" source for second part of crypt seed pattern */ 85 | # ifndef ZCR_SEED2 86 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 87 | # endif 88 | 89 | static int crypthead(const char* passwd, /* password string */ 90 | unsigned char* buf, /* where to write header */ 91 | int bufSize, 92 | unsigned long* pkeys, 93 | const unsigned long* pcrc_32_tab, 94 | unsigned long crcForCrypting) 95 | { 96 | int n; /* index in random header */ 97 | int t; /* temporary */ 98 | int c; /* random byte */ 99 | unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 100 | static unsigned calls = 0; /* ensure different random header each time */ 101 | 102 | if (bufSize> 7) & 0xff; 117 | header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 118 | } 119 | /* Encrypt random header (last two bytes is high word of crc) */ 120 | init_keys(passwd, pkeys, pcrc_32_tab); 121 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 122 | { 123 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 124 | } 125 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 126 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 127 | return n; 128 | } 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/minizip/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project 3 | 4 | Copyright (C) 1998-2010 Gilles Vollant 5 | http://www.winimage.com/zLibDll/minizip.html 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson 8 | http://result42.com 9 | 10 | This program is distributed under the terms of the same license as zlib. 11 | See the accompanying LICENSE file for the full text of the license. 12 | */ 13 | 14 | #ifndef _ZLIBIOAPI64_H 15 | #define _ZLIBIOAPI64_H 16 | 17 | #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) 18 | # ifndef __USE_FILE_OFFSET64 19 | # define __USE_FILE_OFFSET64 20 | # endif 21 | # ifndef __USE_LARGEFILE64 22 | # define __USE_LARGEFILE64 23 | # endif 24 | # ifndef _LARGEFILE64_SOURCE 25 | # define _LARGEFILE64_SOURCE 26 | # endif 27 | # ifndef _FILE_OFFSET_BIT 28 | # define _FILE_OFFSET_BIT 64 29 | # endif 30 | #endif 31 | 32 | #include 33 | #include 34 | #include "zlib.h" 35 | 36 | #if defined(USE_FILE32API) 37 | # define fopen64 fopen 38 | # define ftello64 ftell 39 | # define fseeko64 fseek 40 | #else 41 | # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) 42 | # define fopen64 fopen 43 | # define ftello64 ftello 44 | # define fseeko64 fseeko 45 | # endif 46 | # ifdef _MSC_VER 47 | # define fopen64 fopen 48 | # if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) 49 | # define ftello64 _ftelli64 50 | # define fseeko64 _fseeki64 51 | # else /* old MSC */ 52 | # define ftello64 ftell 53 | # define fseeko64 fseek 54 | # endif 55 | # endif 56 | #endif 57 | 58 | /* a type choosen by DEFINE */ 59 | #ifdef HAVE_64BIT_INT_CUSTOM 60 | typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; 61 | #else 62 | # ifdef HAS_STDINT_H 63 | # include "stdint.h" 64 | typedef uint64_t ZPOS64_T; 65 | # else 66 | # if defined(_MSC_VER) || defined(__BORLANDC__) 67 | typedef unsigned __int64 ZPOS64_T; 68 | # else 69 | typedef unsigned long long int ZPOS64_T; 70 | # endif 71 | # endif 72 | #endif 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 79 | #define ZLIB_FILEFUNC_SEEK_END (2) 80 | #define ZLIB_FILEFUNC_SEEK_SET (0) 81 | 82 | #define ZLIB_FILEFUNC_MODE_READ (1) 83 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 84 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 85 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 86 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 87 | 88 | #ifndef ZCALLBACK 89 | # if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \ 90 | defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 91 | # define ZCALLBACK CALLBACK 92 | # else 93 | # define ZCALLBACK 94 | # endif 95 | #endif 96 | 97 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 98 | typedef voidpf (ZCALLBACK *opendisk_file_func) OF((voidpf opaque, voidpf stream, int number_disk, int mode)); 99 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 100 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 101 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 102 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 103 | 104 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 105 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 106 | 107 | /* here is the "old" 32 bits structure structure */ 108 | typedef struct zlib_filefunc_def_s 109 | { 110 | open_file_func zopen_file; 111 | opendisk_file_func zopendisk_file; 112 | read_file_func zread_file; 113 | write_file_func zwrite_file; 114 | tell_file_func ztell_file; 115 | seek_file_func zseek_file; 116 | close_file_func zclose_file; 117 | testerror_file_func zerror_file; 118 | voidpf opaque; 119 | } zlib_filefunc_def; 120 | 121 | typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); 122 | typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 123 | typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); 124 | typedef voidpf (ZCALLBACK *opendisk64_file_func)OF((voidpf opaque, voidpf stream, int number_disk, int mode)); 125 | 126 | typedef struct zlib_filefunc64_def_s 127 | { 128 | open64_file_func zopen64_file; 129 | opendisk64_file_func zopendisk64_file; 130 | read_file_func zread_file; 131 | write_file_func zwrite_file; 132 | tell64_file_func ztell64_file; 133 | seek64_file_func zseek64_file; 134 | close_file_func zclose_file; 135 | testerror_file_func zerror_file; 136 | voidpf opaque; 137 | } zlib_filefunc64_def; 138 | 139 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 140 | void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); 141 | 142 | /* now internal definition, only for zip.c and unzip.h */ 143 | typedef struct zlib_filefunc64_32_def_s 144 | { 145 | zlib_filefunc64_def zfile_func64; 146 | open_file_func zopen32_file; 147 | opendisk_file_func zopendisk32_file; 148 | tell_file_func ztell32_file; 149 | seek_file_func zseek32_file; 150 | } zlib_filefunc64_32_def; 151 | 152 | #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 153 | #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 154 | /*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/ 155 | /*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/ 156 | #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 157 | #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) 158 | 159 | voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); 160 | voidpf call_zopendisk64 OF((const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, int number_disk, int mode)); 161 | long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); 162 | ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); 163 | 164 | void fill_zlib_filefunc64_32_def_from_filefunc32 OF((zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)); 165 | 166 | #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) 167 | #define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode))) 168 | #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) 169 | #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) 170 | 171 | #ifdef __cplusplus 172 | } 173 | #endif 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/SSZipArchive/minizip/mztools.h: -------------------------------------------------------------------------------- 1 | /* 2 | Additional tools for Minizip 3 | Code: Xavier Roche '2004 4 | License: Same as ZLIB (www.gzip.org) 5 | */ 6 | 7 | #ifndef _zip_tools_H 8 | #define _zip_tools_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #ifndef _ZLIB_H 15 | #include "zlib.h" 16 | #endif 17 | 18 | #include "unzip.h" 19 | 20 | /* Repair a ZIP file (missing central directory) 21 | file: file to recover 22 | fileOut: output file after recovery 23 | fileOutTmp: temporary file name used for recovery 24 | */ 25 | extern int ZEXPORT unzRepair(const char* file, 26 | const char* fileOut, 27 | const char* fileOutTmp, 28 | uLong* nRecovered, 29 | uLong* bytesRecovered); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/ZXLSXParsers注解.m: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // NSString+ZXLSXParsers__.h 3 | // ZXLSXReader 4 | // 5 | // Created by Casanova.Z/朱静宁 16/8/24. 6 | // 博 客 :http://blog.sina.com.cn/casanovaZHU 7 | // E-mail :casanova.z@qq.com 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | /* 13 | xlsx文件的解析步骤 14 | 因为xlsx文件可以解压,在解压的文件中有相应的内容部署情况记录 15 | 在xl文件夹下的sheet文件中记录着每个格子(A1,A2)的值在shareStrings在文件中的位置索引, 16 | 解析这两个文件就可得到对应的xlsx的文件内容 17 | 18 | 19 | 1. 解压缩,用第三方库SSZipArchive,需导入libz.tbd库 20 | 2. xml解析xl下的workbook.xml文件查询到底有几个sheet文件 21 | 3. 解析sheet中的数据,得到具体值在sharedStrings.xml中的索引, 22 | 4. 封装数据,返回其中已经有多线程了,不必自添加多线程执行此任务 23 | 24 | // 使用方法 25 | 1.创建ZXLSXParser对象, 26 | + (instancetype)defaultZXLSXParser; 27 | 28 | 2.设置要解析的文件路径 29 | NSString *unzipFilePath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"xlsx"]; 30 | [_xmlPaser setParseFilePath:unzipFilePath]; 31 | 32 | 3.设置输出数据时的格式 33 | [_xmlPaser setParseOutType:ZParseOutTypeJson]; // JSON字符串格式 34 | // [_xmlPaser setParseOutType:ZParseOutTypeArrayObj];// 数组中存放的是ZContent对象 35 | // [_xmlPaser setParseOutType:ZParseOutTypeArrayDict];// 数组中盛放的是字典,每个字典存放每一格的相关数据 36 | 37 | 4.设置代理,处理结果,设置的ParseOutType类型,在返回接受处理的时候要类型匹配 38 | _xmlPaser.delegate = self; 39 | 40 | 5.开始解析 41 | [_xmlPaser parse]; 42 | 43 | */ 44 | 45 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/ZBaseParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZBaseParser.h 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import 13 | 14 | @interface ZBaseParser : NSObject 15 | 16 | @property (nonatomic, copy) NSString *parseFilePath; // 要解析的文件路径 17 | @property (nonatomic, strong) NSXMLParser *xmlParser; // xml解析器 18 | @property (nonatomic, copy) NSString *currentElement; // 当前节点的名称 19 | 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/ZBaseParser.m: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZBaseParser.m 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import "ZBaseParser.h" 13 | 14 | @implementation ZBaseParser 15 | 16 | - (NSXMLParser *)xmlParser { 17 | 18 | if (!_xmlParser) { 19 | 20 | NSData *data = [[NSData alloc] initWithContentsOfFile:self.parseFilePath]; 21 | _xmlParser = [[NSXMLParser alloc] initWithData:data]; 22 | } 23 | return _xmlParser; 24 | } 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/ZContentParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZContentParser.h 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import "ZBaseParser.h" 13 | #import "ZPaserProtocol.h" 14 | 15 | @interface ZContentParser : ZBaseParser 16 | 17 | @property (nonatomic, strong) NSDictionary *allColDict; // 从所有sheet解析出的col的信息 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/ZContentParser.m: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZContentParser.m 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import "ZContentParser.h" 13 | #import "ZContent.h" 14 | #import "ZSheetCol.h" 15 | #import "config.h" 16 | 17 | @interface ZContentParser () 18 | { 19 | NSString *currentSheetName; // 当前文件(sheet)名称 20 | 21 | } 22 | @property (nonatomic, strong) NSMutableArray *contentArr; // 存储所有的解析出的数据 23 | @property (nonatomic, copy) NSMutableString *currentString; // 当前解析出来的数据 24 | @property (nonatomic, strong) NSMutableArray *vArr; // 记录sharedString.xml中的数据是否已经被引用了,如果应用了,则会重复操作同一个数据,因为如果在数据内容相同,在sharedString.xml中是不会重复出现的(so 在解析的时候,如果值有重复,contenArr相对就会缺少一个),故如果已经被使用,则需要在重新添加对象,设置其值, 25 | 26 | 27 | @end 28 | 29 | 30 | @implementation ZContentParser 31 | 32 | 33 | - (NSMutableArray *)vArr { 34 | 35 | if (!_vArr) { 36 | _vArr = [NSMutableArray array]; 37 | } 38 | return _vArr; 39 | } 40 | 41 | - (NSMutableArray *)contentArr { 42 | 43 | if (!_contentArr) { 44 | _contentArr = [NSMutableArray array]; 45 | } 46 | return _contentArr; 47 | } 48 | 49 | - (NSMutableString *)currentString { 50 | 51 | if (!_currentString) { 52 | _currentString = [NSMutableString stringWithFormat:@""]; 53 | } 54 | return _currentString; 55 | } 56 | /** 57 | * 开始解析 58 | * 59 | * @return 解析出的数据 60 | */ 61 | - (id)startParse { 62 | 63 | // 指定要解析的文件的路径 64 | NSString *path = [NSString stringWithFormat:@"%@/xl/sharedStrings.xml",destinationPath]; 65 | self.parseFilePath = path; 66 | 67 | // 进行解析, 68 | self.xmlParser.delegate = self; 69 | [self.xmlParser parse]; 70 | 71 | return [self makeContent]; 72 | } 73 | 74 | //准备节点 75 | - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName attributes:(NSDictionary *)attributeDict{ 76 | 77 | self.currentElement = elementName; 78 | } 79 | 80 | // 3. 查找节点内容,可能会多次 81 | - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 82 | { 83 | if ([self.currentElement isEqualToString:@"t"]) { 84 | 85 | [self.currentString appendString:string]; 86 | } 87 | } 88 | 89 | //解析完一个节点 90 | - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName{ 91 | 92 | if ([elementName isEqualToString:@"t"]) { 93 | 94 | ZContent *content = [[ZContent alloc] init]; 95 | content.value = self.currentString; 96 | self.currentString = nil; 97 | [self.contentArr addObject:content]; 98 | } 99 | } 100 | 101 | - (void)parserDidEndDocument:(NSXMLParser *)parser { 102 | 103 | self.xmlParser = nil; 104 | } 105 | 106 | 107 | /** 108 | * 为content对象填充keyName数据 109 | * 110 | * @return 填充后的最终数据 111 | */ 112 | - (NSArray *)makeContent{ 113 | 114 | if(self.allColDict && self.allColDict.count > 0){ 115 | NSArray *arrKeys = self.allColDict.allKeys; 116 | // 索引里每个格子的索引都有,只是格子中为数字的索引中直接就是数据,如果为中文或者英文的,则为格子内容的索引,故此处的索引个数是对的,但是到后面解析的时候,从sharedStrings.xml中解析出来的数据要比索引个数少,因为数字的内容直接就在索引文件中显示,sharedStrings.xml文件里没有在体现, 117 | // 故这里要做的是将已经有的对象属性进行填充,并对没有添加的对象进行添加,实现个数对等 118 | for (int i = 0; i < arrKeys.count; i++) { 119 | 120 | NSString *sheetName = arrKeys[i]; 121 | NSArray *arr = self.allColDict[sheetName]; 122 | for (int j = 0 ; j < arr.count; j++) { 123 | 124 | ZSheetCol *sheetCol = arr[j]; 125 | if([sheetCol.t isEqualToString:@"s"]){ 126 | 127 | NSInteger v = [sheetCol.v integerValue]; 128 | if ([self.vArr containsObject:sheetCol.v]) { 129 | 130 | ZContent *content = [[ZContent alloc] init]; 131 | content.keyName = sheetCol.r; 132 | content.sheetName = sheetName; 133 | content.value = self.contentArr[v].value; 134 | [self.contentArr addObject:content]; 135 | }else{ 136 | 137 | self.contentArr[v].keyName = sheetCol.r; 138 | self.contentArr[v].sheetName = sheetName; 139 | [self.vArr addObject:sheetCol.v]; // 标记是否已经使用过该值 140 | } 141 | }else{ 142 | ZContent *content = [[ZContent alloc] init]; 143 | content.keyName = sheetCol.r; 144 | content.sheetName = sheetName; 145 | content.value = sheetCol.v; 146 | [self.contentArr addObject:content]; 147 | } 148 | } 149 | } 150 | } 151 | [self sortArrayAsc]; 152 | return self.contentArr; 153 | } 154 | 155 | 156 | /** 157 | * 给数组排序,先判断sheet中的sheetName的大小 158 | * 后再sheetName相同的情况下判断的keyName的大小 159 | * 160 | * @param arr 需要排序的数组 161 | */ 162 | - (void)sortArrayAsc{ 163 | 164 | [self.contentArr sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) { 165 | 166 | ZContent *content1 = (ZContent *)obj1; 167 | ZContent *content2 = (ZContent *)obj2; 168 | if (content1.sheetName > content2.sheetName) { 169 | return YES; 170 | }else{ 171 | return NO; 172 | } 173 | }]; 174 | 175 | [self.contentArr sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) { 176 | 177 | ZContent *content1 = (ZContent *)obj1; 178 | ZContent *content2 = (ZContent *)obj2; 179 | if ([content1.sheetName isEqualToString:content2.sheetName]&&content1.keyName > content2.keyName) { 180 | return YES; 181 | }else{ 182 | return NO; 183 | } 184 | }]; 185 | } 186 | @end 187 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/ZSheetParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZSheetParser.h 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import "ZBaseParser.h" 13 | #import "ZPaserProtocol.h" 14 | 15 | @interface ZSheetParser : ZBaseParser 16 | 17 | @property (nonatomic, strong) NSArray *sheetArr; // 从workbook解析出的sheet的名称等信息 18 | 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/ZSheetParser.m: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZSheetParser.m 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import "ZSheetParser.h" 13 | #import "ZSheetCol.h" 14 | #import "config.h" 15 | #import "ZSheet.h" 16 | 17 | 18 | @interface ZSheetParser () 19 | { 20 | NSString *currentRowNum; // 当前数据所处的行数 21 | NSString *currentIndexValue; // 当前列中持有的索引 22 | } 23 | @property (nonatomic, strong) NSMutableDictionary *allColDict; // 存储了多个sheet里的信息 24 | @property (nonatomic, strong) NSMutableArray *colArr; // 存储所有col的信息 25 | @property (nonatomic, strong) ZSheetCol *sheetCol; // 每一个基点的数据 26 | @end 27 | 28 | 29 | @implementation ZSheetParser 30 | 31 | #pragma -mark 列的信息集合 32 | 33 | - (NSMutableDictionary *)allColDict { 34 | 35 | if (!_allColDict) { 36 | _allColDict = [NSMutableDictionary dictionary]; 37 | } 38 | return _allColDict; 39 | } 40 | 41 | /** 42 | * 开始解析 43 | * 44 | * @return 解析出的数据 45 | */ 46 | - (id)startParse { 47 | 48 | for (int i = 0; i < self.sheetArr.count; i++) { 49 | 50 | _colArr = [NSMutableArray array]; 51 | currentRowNum = 0; 52 | ZSheet *sheet = self.sheetArr[i]; 53 | NSString *sheetPath = [NSString stringWithFormat:@"%@/xl/worksheets/%@.xml",destinationPath,sheet.name.lowercaseString]; 54 | 55 | self.parseFilePath = sheetPath; 56 | self.xmlParser.delegate = self; 57 | [self.xmlParser parse]; 58 | self.allColDict[sheet.name] = self.colArr; 59 | _colArr = nil; 60 | } 61 | 62 | return self.allColDict; 63 | } 64 | 65 | //准备节点 66 | - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName attributes:(NSDictionary *)attributeDict{ 67 | 68 | self.currentElement = elementName; 69 | if ([self.currentElement isEqualToString:@"row"]) { 70 | 71 | currentRowNum = attributeDict[@"r"]; 72 | }else if ([self.currentElement isEqualToString:@"c"]) { 73 | 74 | self.sheetCol = [[ZSheetCol alloc] init]; 75 | self.sheetCol.row = currentRowNum; 76 | self.sheetCol.r = attributeDict[@"r"]; 77 | self.sheetCol.s = attributeDict[@"s"]!=nil?attributeDict[@"s"]:@""; 78 | self.sheetCol.t = attributeDict[@"t"]!=nil?attributeDict[@"t"]:@""; 79 | } 80 | } 81 | 82 | // 3. 查找节点内容,可能会多次 83 | - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 84 | { 85 | 86 | self.sheetCol.v = string; 87 | [self.colArr addObject:self.sheetCol]; 88 | } 89 | 90 | ////解析完一个节点 91 | //- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName{ 92 | // 93 | //} 94 | 95 | - (void)parserDidEndDocument:(NSXMLParser *)parser { 96 | 97 | self.xmlParser = nil; 98 | self.currentElement = @""; 99 | currentRowNum = @""; 100 | } 101 | 102 | 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/ZWorkbookParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZWorkbookParser.h 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | #import 12 | #import "ZPaserProtocol.h" 13 | #import "ZBaseParser.h" 14 | 15 | @interface ZWorkbookParser : ZBaseParser 16 | 17 | 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/ZWorkbookParser.m: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZWorkbookParser.m 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import "ZWorkbookParser.h" 13 | #import "ZSheet.h" 14 | #import "config.h" 15 | 16 | @interface ZWorkbookParser () 17 | 18 | @property (nonatomic, strong) ZSheet *sheet; // sheet数据模型 19 | @property (nonatomic, strong) NSMutableArray *sheetArr; // 存放workbook中解析出的sheet的信息 20 | 21 | @end 22 | 23 | 24 | @implementation ZWorkbookParser 25 | 26 | #pragma -mark 懒加载 27 | - (NSMutableArray *)sheetArr { 28 | 29 | if (!_sheetArr) { 30 | _sheetArr = [NSMutableArray array]; 31 | } 32 | return _sheetArr; 33 | } 34 | 35 | /** 36 | * 开始解析 37 | * 38 | * @return 解析出的数据 39 | */ 40 | - (id)startParse { 41 | 42 | NSString *workbookPath = [NSString stringWithFormat:@"%@%@",destinationPath,@"/xl/workbook.xml"]; 43 | [self setParseFilePath:workbookPath]; 44 | self.xmlParser.delegate = self; 45 | if([self.xmlParser parse]){ 46 | return self.sheetArr; 47 | } 48 | return nil; 49 | } 50 | 51 | //准备节点 52 | - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName attributes:(NSDictionary *)attributeDict{ 53 | 54 | self.currentElement = elementName; 55 | if ([self.currentElement isEqualToString:@"sheet"]) { 56 | self.sheet = [[ZSheet alloc] init]; 57 | self.sheet.name = attributeDict[@"name"]; 58 | self.sheet.sheetId = attributeDict[@"sheetId"]; 59 | self.sheet.rid = attributeDict[@"r:id"]; 60 | [self.sheetArr addObject:self.sheet]; 61 | } 62 | } 63 | 64 | //解析完一个节点 65 | - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName{ 66 | 67 | self.currentElement = nil; 68 | } 69 | 70 | - (void)parserDidEndDocument:(NSXMLParser *)parser { 71 | 72 | self.xmlParser = nil; 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/ZXLSXParser.h: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZXMLParser.h 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import 13 | 14 | /** 15 | 解析xlsx之后数据存储的格式 16 | */ 17 | typedef enum : NSUInteger { 18 | 19 | ZParseOutTypeJson = 1, // json字符串格式 20 | ZParseOutTypeArrayObj, // 数组盛放对象格式 21 | ZParseOutTypeArrayDict // 数组盛放字典格式 22 | } ZParseOutType; 23 | 24 | @class ZXLSXParser; 25 | 26 | @protocol ZXLSXParserDelegate 27 | 28 | @required 29 | 30 | /** 31 | * 处理解析的结果 32 | * 33 | * @param parser 解析器 34 | * @param responseObj 解析结果 35 | * @param error 解析错误 36 | */ 37 | - (void)parser:(ZXLSXParser *)parser success:(id)responseObj; 38 | 39 | 40 | @end 41 | 42 | 43 | @interface ZXLSXParser : NSObject 44 | 45 | @property (nonatomic, weak) id delegate; // 回调处理 46 | @property (nonatomic, copy) NSString *parseFilePath; // 等待解析的文件路径 47 | @property (nonatomic, assign) ZParseOutType parseOutType; // 解析后数据的输出类型 48 | 49 | /** 50 | * 得到当前的xmlParser的解析对象 51 | * 52 | * @return 对象 53 | */ 54 | + (instancetype)defaultZXLSXParser; 55 | 56 | /** 57 | * 开始解析 58 | * 59 | * @return 解析后的数据 60 | */ 61 | - (void)parse; 62 | 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/ZXLSXParser.m: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZXMLParser.m 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import "ZXLSXParser.h" 13 | #import "config.h" 14 | #import "SSZipArchive.h" 15 | #import "ZWorkbookParser.h" 16 | #import "ZSheetParser.h" 17 | #import "ZContentParser.h" 18 | #import "ZContent.h" 19 | 20 | @interface ZXLSXParser () 21 | 22 | 23 | @property (nonatomic, strong) ZWorkbookParser *wbParser; // workbookParser的解析器 24 | @property (nonatomic, strong) ZSheetParser *sheetParser; // sheetParser的解析器 25 | @property (nonatomic, strong) ZContentParser *contentParser;// 内容的解析器 26 | 27 | 28 | @end 29 | 30 | @implementation ZXLSXParser 31 | 32 | + (instancetype)defaultZXLSXParser { 33 | 34 | static ZXLSXParser *_xLSXParser; 35 | static dispatch_once_t onceToken; 36 | dispatch_once(&onceToken, ^{ 37 | 38 | _xLSXParser = [[ZXLSXParser alloc] init]; 39 | }); 40 | 41 | return _xLSXParser; 42 | } 43 | 44 | - (ZParseOutType)parseOutType { 45 | 46 | if(!_parseOutType){ 47 | _parseOutType = ZParseOutTypeArrayObj; 48 | } 49 | return _parseOutType; 50 | } 51 | 52 | 53 | - (void)parse { 54 | 55 | __weak typeof(self) weakSelf = self; 56 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 57 | 58 | // 解压xlsx文件 59 | [SSZipArchive unzipFileAtPath:self.parseFilePath toDestination:destinationPath]; 60 | 61 | // 解析workbook.xml文件 62 | NSArray *sheetArr = [weakSelf parseWorkbook]; 63 | 64 | // 解析sheet文件,获取具体值在sharedString.xml中的索引 65 | NSDictionary *dict = [weakSelf parseSheetWithSheetArr:sheetArr]; 66 | 67 | // 解析最终结果 68 | NSArray *result = [weakSelf parseSharedStringsWithAllColDict:dict]; 69 | 70 | if([_delegate respondsToSelector:@selector(parser:success:)]){ 71 | 72 | id finalResult = [weakSelf makeOutContent:result]; 73 | [weakSelf.delegate parser:weakSelf success:finalResult]; 74 | }else{ 75 | NSLog(@"delegate is fail...."); 76 | } 77 | 78 | // 删除临时文件 79 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 80 | 81 | NSFileManager *fileManager = [NSFileManager defaultManager]; 82 | if([fileManager fileExistsAtPath:destinationPath]){ 83 | NSError *error; 84 | if([fileManager removeItemAtPath:destinationPath error:&error]&& !error){ 85 | // NSLog(@"file remove success...."); 86 | }else if(error){ 87 | NSLog(@"file remove failure.... error:%@",error); 88 | } 89 | } 90 | }); 91 | }); 92 | } 93 | 94 | /** 95 | * 解析workbook.xml中的数据 96 | * 97 | * @return sheet的集合数组 98 | */ 99 | - (NSArray *)parseWorkbook{ 100 | 101 | _wbParser = [[ZWorkbookParser alloc] init]; 102 | return [_wbParser startParse]; 103 | } 104 | 105 | 106 | /** 107 | * 解析每个sheet文件 108 | * 109 | * @return 解析出的数据数组 110 | */ 111 | - (NSDictionary *)parseSheetWithSheetArr:(NSArray *)arr { 112 | 113 | _sheetParser = [[ZSheetParser alloc] init]; 114 | [_sheetParser setSheetArr:arr]; 115 | return [_sheetParser startParse]; 116 | } 117 | 118 | /** 119 | * 根据索引从sharedStrings.xml中解析数据 120 | * 121 | * @param dict 从sheet中解析出来的索引数据 122 | * 123 | * @return 对应的数据数组 124 | */ 125 | - (NSArray *)parseSharedStringsWithAllColDict:(NSDictionary *)dict { 126 | 127 | _contentParser = [[ZContentParser alloc] init]; 128 | [_contentParser setAllColDict:dict]; 129 | return [_contentParser startParse]; 130 | } 131 | 132 | /** 133 | * 根据设置的输出数据格式,重组数据 134 | * 135 | * @return 重组后的数据 136 | */ 137 | - (id)makeOutContent:(NSArray *)resultArr { 138 | 139 | id resultObj = nil; 140 | 141 | switch (self.parseOutType) { 142 | case ZParseOutTypeJson: 143 | 144 | resultObj = [self makeJsonString:resultArr]; 145 | break; 146 | 147 | case ZParseOutTypeArrayObj: 148 | 149 | resultObj = resultArr; 150 | break; 151 | 152 | case ZParseOutTypeArrayDict: 153 | resultObj = [self makeArrayDictWithResultArray:resultArr]; 154 | break; 155 | 156 | default: 157 | resultObj = nil; 158 | break; 159 | } 160 | 161 | return resultObj; 162 | } 163 | 164 | /** 165 | * 将结果集合组合成json字符串 166 | * 167 | * @param arr 结果集合 168 | * 169 | * @return json字符串 170 | */ 171 | - (NSString *)makeJsonString:(NSArray *)arr { 172 | 173 | NSError *error; 174 | NSArray *dictArr = [self makeArrayDictWithResultArray:arr]; 175 | NSData *data = [NSJSONSerialization dataWithJSONObject:dictArr options:NSJSONWritingPrettyPrinted error:&error]; 176 | if (error) { 177 | NSLog(@"error:%@",error); 178 | }else{ 179 | NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 180 | return jsonString; 181 | } 182 | return nil; 183 | } 184 | 185 | /** 186 | * 将结果集合组合成数组加字典的形式 187 | * 188 | * @param arr 结果集合 189 | * 190 | * @return 结果集合 191 | */ 192 | - (NSArray *)makeArrayDictWithResultArray:(NSArray *)arr { 193 | 194 | NSMutableArray *resultArr = [NSMutableArray array]; 195 | for(int i = 0;i< arr.count;i++){ 196 | 197 | ZContent *content = arr[i]; 198 | NSMutableDictionary *dict = [NSMutableDictionary dictionary]; 199 | dict[@"sheetName"] = content.sheetName; 200 | dict[@"keyName"] = content.keyName; 201 | dict[@"value"] = content.value; 202 | [resultArr addObject:dict]; 203 | } 204 | return resultArr; 205 | } 206 | 207 | 208 | 209 | @end 210 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/config.h: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // ZXLSXReader 3 | // 4 | // Created by Casanova.Z/朱静宁 16/8/24. 5 | // 博 客 :http://blog.sina.com.cn/casanovaZHU 6 | // E-mail :casanova.z@qq.com 7 | // 8 | // Copyright © 2016年 casanova. All rights reserved. 9 | /******************************************************/ 10 | 11 | #ifndef config_h 12 | #define config_h 13 | 14 | /** 15 | * xlsx解压后的目录 16 | */ 17 | #define destinationPath [NSTemporaryDirectory() stringByAppendingPathComponent:@"ZTMP_UNZIP_XLSX_FILES/"] 18 | 19 | #endif /* config_h */ 20 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/models/ZContent.h: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZContent.h 5 | // Author : Casanova.Z/朱静宁 16/8/25. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import 13 | 14 | @interface ZContent : NSObject 15 | 16 | @property (nonatomic, copy) NSString *sheetName; // 所在文件的名称(sheet1,sheet2) 17 | @property (nonatomic, copy) NSString *keyName; // 在sheet中的标示(A1,B3) 18 | @property (nonatomic, copy) NSString *value; // 对应文件下对应标识下的值 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/models/ZContent.m: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZContent.m 5 | // Author : Casanova.Z/朱静宁 16/8/25. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import "ZContent.h" 13 | 14 | static NSString *kSheetName = @"sheetName"; // 所在文件的名称(sheet1,sheet2) 15 | static NSString *kKeyName = @"keyName"; // 在sheet中的标示(A1,B3) 16 | static NSString *kValue = @"value"; // 对应文件下对应标识下的值 17 | 18 | @implementation ZContent 19 | 20 | 21 | - (NSString *)description { 22 | 23 | return [NSString stringWithFormat:@"sheetName:%@ keyName:%@ value:%@",self.sheetName,self.keyName,self.value]; 24 | } 25 | 26 | 27 | - (void)encodeWithCoder:(NSCoder *)aCoder { 28 | 29 | [aCoder encodeObject:self.sheetName forKey:kSheetName]; 30 | [aCoder encodeObject:self.keyName forKey:kKeyName]; 31 | [aCoder encodeObject:self.value forKey:kValue]; 32 | } 33 | - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { 34 | 35 | if (self = [super init]) { 36 | self.sheetName = [aDecoder decodeObjectForKey:kSheetName]; 37 | self.keyName = [aDecoder decodeObjectForKey:kKeyName]; 38 | self.value = [aDecoder decodeObjectForKey:kValue]; 39 | } 40 | return self; 41 | } 42 | 43 | 44 | 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/models/ZPaserProtocol.h: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // NSString+ZPaserProtocol.h 3 | // ZXLSXReader 4 | // 5 | // Created by Casanova.Z/朱静宁 16/8/24. 6 | // 博 客 :http://blog.sina.com.cn/casanovaZHU 7 | // E-mail :casanova.z@qq.com 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | 13 | /** 14 | * 此文件规范解析类所具有的功能 15 | */ 16 | #import 17 | 18 | @protocol ZPaserProtocol 19 | 20 | 21 | @required 22 | 23 | /** 24 | * 开始解析 25 | * 26 | * @return 解析出的数据 27 | */ 28 | - (id)startParse; 29 | 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/models/ZSheet.h: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZWorkbook.h 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import 13 | 14 | @interface ZSheet : NSObject 15 | 16 | @property (nonatomic, copy) NSString *name; // sheet的name属性值 17 | @property (nonatomic, copy) NSString *sheetId; // sheet的sheetId属性值 18 | @property (nonatomic, copy) NSString *rid; // sheet的r:id属性值 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/models/ZSheet.m: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZWorkbook.m 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import "ZSheet.h" 13 | 14 | @implementation ZSheet 15 | 16 | - (NSString *)description { 17 | 18 | return [NSString stringWithFormat:@"name:%@ sheetId:%@ rid:%@",self.name,self.sheetId,self.rid]; 19 | } 20 | 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/models/ZSheetCol.h: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZSheetCol.h 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | 13 | /** 14 | * 此文件为sheet中解析出来的每列中的数据 15 | */ 16 | 17 | #import 18 | 19 | @interface ZSheetCol : NSObject 20 | 21 | @property (nonatomic, copy) NSString *r; // sheet中的c节点中属性r 22 | @property (nonatomic, copy) NSString *s; // sheet中的c节点中属性s 23 | @property (nonatomic, copy) NSString *t; // sheet中的c节点中属性t 24 | @property (nonatomic, copy) NSString *v; // sheet中的c节点中属性v 25 | @property (nonatomic, copy) NSString *row; // sheet中的c列所处的行号 26 | 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ExcelParser/XLSX/xmlParser/models/ZSheetCol.m: -------------------------------------------------------------------------------- 1 | /******************************************************/ 2 | // 3 | // ProjectName: ZXLSXReader 4 | // FileName : ZSheetCol.m 5 | // Author : Casanova.Z/朱静宁 16/8/24. 6 | // E-mail : casanova.z@qq.com 7 | // Blog : http://blog.sina.com.cn/casanovaZHU 8 | // 9 | // Copyright © 2016年 casanova. All rights reserved. 10 | /******************************************************/ 11 | 12 | #import "ZSheetCol.h" 13 | 14 | @implementation ZSheetCol 15 | 16 | 17 | - (NSString *)description { 18 | 19 | return [NSString stringWithFormat:@"row:%@ r:%@ t:%@ v:%@",self.row,self.r,self.t,self.v]; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /ExcelDemo/ExcelDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ExcelDemo 4 | // 5 | // Created by molangwu on 2017/8/17. 6 | // Copyright © 2017年 molangwu. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController, LAWExcelParserDelegate { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | @IBAction func parserAction(_ sender: Any) { 24 | 25 | guard let path = Bundle.main.path(forResource: "test3", ofType: "xlsx") else { 26 | print("文件没找到") 27 | return 28 | } 29 | 30 | LAWExcelTool.shareInstance().delegate = self 31 | 32 | LAWExcelTool.shareInstance().parserExcel(withPath: path) 33 | 34 | } 35 | 36 | //LAWExcelParserDelegate 37 | func parser(_ parser: LAWExcelTool!, success responseObj: Any!) { 38 | print(responseObj) 39 | } 40 | 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /ExcelDemo/test.csv: -------------------------------------------------------------------------------- 1 | 运单编号,收/派件员,计费重量,签收省份,首重,续重,费用 2 | 719819806047,Hangyin,0.2,Anhui,6,2.5,6 3 | 535053121266,Hangyin,1.3,Fujian,6,2,8 -------------------------------------------------------------------------------- /ExcelDemo/test.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/molangwu/ExcelParseForIOS/99aa19bbc75d79c991a579f62773037177018494/ExcelDemo/test.xls -------------------------------------------------------------------------------- /ExcelDemo/test3.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/molangwu/ExcelParseForIOS/99aa19bbc75d79c991a579f62773037177018494/ExcelDemo/test3.xlsx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 前言 2 | 由于项目需要解析excel,在网上找了很久,都没有找到一个齐全的轮子,所以我修改和整合了网上的解析excel教程。 3 | ##教程介绍 4 | ####1.解析csv 5 | - CSV: 6 | 即逗号分隔值,其文件以纯文本形式存储表格数据(数字和文本)。 7 | - 解析思路: 8 | 读取该文件,根据\n和,来解析出excel数据 9 | \n用来区分excel的行 10 | ,用来区分excel的列 11 | 12 | ####2.解析 xls: 13 | - xls 14 | 就是 Microsoft Excel 工作表,是一种非常常用的电子表格格式。 15 | - 解析思路 16 | 通过DHxlsReader框架来实现解析 17 | 18 | ####3.解析xlsx 19 | - xlsx 20 | 即Microsoft Office EXCEL 2007/2010/2013/2016文档的扩展名 21 | - 解析思路 22 | 07版之后的excel基本都是xlsx格式的,其本质上其实是一个压缩文件,打开之后是一个文件夹,如下图 23 | 24 | ![1.png](http://upload-images.jianshu.io/upload_images/2814521-b1da8fb3792f95e2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 25 | 26 | ![2.png](http://upload-images.jianshu.io/upload_images/2814521-1495c05d35b65a00.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 27 | 28 | 我们来分析一下这个文件夹的结构;shareString是一个公共的字符串池,相当于,给我们表中字符串贴上一个标签一样.然后我们先分析一下shareString.xml里面的内容 29 | 30 | ----- 31 | ![3.png](http://upload-images.jianshu.io/upload_images/2814521-c1f636df409757cb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 32 | 33 | 下面来解析worksheet中sheet1.xml 34 | 35 | ----- 36 | ![4.png](http://upload-images.jianshu.io/upload_images/2814521-95becc1395474a58.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 37 | 38 | 然后就这样循环的查下去,把你需要的内容查找出来 39 | 40 | - 具体做法 41 | - 解压缩,用第三方库SSZipArchive,需导入libz.tbd库 42 | - xml解析xl下的workbook.xml文件查询到底有几个sheet文件 43 | - 解析sheet中的数据,得到具体值在sharedStrings.xml中的索引, 44 | - 封装数据,返回其中已经有多线程了,不必自添加多线程执行此任务 45 | 46 | ----- 47 | ## 教程安装和使用 48 | - 把ExcelParser文件夹拷贝的项目里面 49 | - 导入libiconv.2.dylib和libz.tbd, 50 | libiconv.2.dylib添加的时候可能要注意一点,要点加号,Add Other...,然后command+shift+g, 输入/usr/lib/ ,你就可以找到了. 51 | - 设置header search Path 52 | 因为DHxlsReader中用到了C的库,所以你的头文件要加上下图所示. 53 | 54 | ![5.png](http://upload-images.jianshu.io/upload_images/2814521-0f83cbaea7c7e901.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 55 | 56 | - 添加 .PCH文件 57 | 否则会提示 NSObjct没找到 58 | 创建一个ExcelDemoDHlibxls-Prefix.pch文件 ,文件内容如下 59 | ```` 60 | // 61 | // Prefix header for all source files of the 'TestDHlibxls' target in the 'TestDHlibxls' project 62 | // 63 | 64 | #import 65 | 66 | #ifndef __IPHONE_4_0 67 | #warning "This project uses features only available in iOS SDK 4.0 and later." 68 | #endif 69 | 70 | #ifdef __OBJC__ 71 | #import 72 | #import 73 | #endif 74 | 75 | ```` 76 | 修改Precompile Prefix Headers 为 yes 77 | 添加.pch文件路径到Prefix Header 如下图 78 | ![E31850E5-5B2C-4C54-B097-3091B9B04E25.png](http://upload-images.jianshu.io/upload_images/2814521-bf9c507834683e2a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 79 | - clean项目 80 | - build项目 81 | 82 | [简书地址](http://www.jianshu.com/u/fc12eeedb47d) 83 | 84 | ---- 85 | 86 | #### 参考链接 87 | 88 | http://www.jianshu.com/p/95c88a7073a6 89 | 90 | http://blog.csdn.net/qxuewei/article/details/51733142 91 | 92 | ---- 93 | 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 94 | --------------------------------------------------------------------------------