Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Formula struct, fix other model types #61

Merged
merged 2 commits into from May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CoreXLSX.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
D12211DC227B555600888BCB /* Formula.swift in Sources */ = {isa = PBXBuildFile; fileRef = D12211DB227B555600888BCB /* Formula.swift */; };
D15021C521A1C31800BFA4FC /* ZIPFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D15021C321A1C31800BFA4FC /* ZIPFoundation.framework */; };
D15021C621A1C31800BFA4FC /* XMLCoder.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D15021C421A1C31800BFA4FC /* XMLCoder.framework */; };
D15021C721A1C33E00BFA4FC /* ZIPFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D15021C321A1C31800BFA4FC /* ZIPFoundation.framework */; };
Expand Down Expand Up @@ -101,6 +102,7 @@
/* Begin PBXFileReference section */
"CoreXLSX::CoreXLSX::Product" /* CoreXLSX.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CoreXLSX.framework; sourceTree = BUILT_PRODUCTS_DIR; };
"CoreXLSX::CoreXLSXTests::Product" /* CoreXLSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = CoreXLSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D12211DB227B555600888BCB /* Formula.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Formula.swift; sourceTree = "<group>"; };
D15021C321A1C31800BFA4FC /* ZIPFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ZIPFoundation.framework; path = Carthage/Build/Mac/ZIPFoundation.framework; sourceTree = "<group>"; };
D15021C421A1C31800BFA4FC /* XMLCoder.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XMLCoder.framework; path = Carthage/Build/Mac/XMLCoder.framework; sourceTree = "<group>"; };
D15021D121A1CA7D00BFA4FC /* CoreXLSX.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CoreXLSX.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -306,6 +308,7 @@
D1A8190821A9CB89004FCA33 /* Worksheet.swift */,
D1EB1B3321B151440043CD1E /* SharedStrings.swift */,
D1BBD9D3223D3D5C00B28C7B /* Styles.swift */,
D12211DB227B555600888BCB /* Formula.swift */,
);
name = CoreXLSXTests;
path = Tests/CoreXLSXTests;
Expand Down Expand Up @@ -724,6 +727,7 @@
D1A8190921A9CB89004FCA33 /* Worksheet.swift in Sources */,
OBJ_91 /* CoreXLSX.swift in Sources */,
OBJ_92 /* Relationships.swift in Sources */,
D12211DC227B555600888BCB /* Formula.swift in Sources */,
OBJ_93 /* XCTestManifests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
5 changes: 5 additions & 0 deletions Sources/CoreXLSX/Relationships.swift
Expand Up @@ -50,6 +50,11 @@ public struct Relationship: Codable, Equatable {
http://schemas.openxmlformats.org/officeDocument/2006/relationships/\
worksheet
"""
case chartsheet =
"""
http://schemas.openxmlformats.org/officeDocument/2006/relationships/\
chartsheet
"""
case sharedStrings =
"""
http://schemas.openxmlformats.org/officeDocument/2006/relationships/\
Expand Down
4 changes: 2 additions & 2 deletions Sources/CoreXLSX/SharedStrings.swift
Expand Up @@ -69,7 +69,7 @@ public struct RichText: Codable, Equatable {

public struct Properties: Codable, Equatable {
public let size: Size
public let color: Color
public let color: Color?
public let font: Font
public let family: Family?
public let scheme: Scheme?
Expand All @@ -83,7 +83,7 @@ public struct RichText: Codable, Equatable {
}
}

public let properties: Properties
public let properties: Properties?

enum CodingKeys: String, CodingKey {
case properties = "rPr"
Expand Down
14 changes: 13 additions & 1 deletion Sources/CoreXLSX/Worksheet/Cell.swift
Expand Up @@ -5,6 +5,8 @@
// Created by Max Desiatov on 24/11/2018.
//

// swiftlint:disable:next line_length
/// [docs](https://wiki.ucl.ac.uk/display/~ucftpw2/2013/10/22/Using+git+for+version+control+of+Excel+spreadsheets+-+part+2+of+3)
public struct Cell: Codable, Equatable {
public let reference: CellReference
public let type: String?
Expand All @@ -15,9 +17,19 @@ public struct Cell: Codable, Equatable {
// element having the same name?
public let s: String?
public let inlineString: InlineString?
public let formula: String?
public let formula: Formula?
public let value: String?

public struct Formula: Codable, Equatable {
public let calculationIndex: Int?
public let value: String?

enum CodingKeys: String, CodingKey {
case calculationIndex = "ca"
case value
}
}

enum CodingKeys: String, CodingKey {
case formula = "f"
case value = "v"
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreXLSX/Worksheet/Worksheet.swift
Expand Up @@ -237,7 +237,7 @@ public struct MergeCell: Codable {
}

public struct InlineString: Codable, Equatable {
let text: String?
public let text: String?

enum CodingKeys: String, CodingKey {
case text = "t"
Expand Down
47 changes: 47 additions & 0 deletions Tests/CoreXLSXTests/Formula.swift
@@ -0,0 +1,47 @@
//
// Formula.swift
// CoreXLSXTests
//
// Created by Max Desiatov on 02/05/2019.
//

@testable import CoreXLSX
import XCTest
import XMLCoder

private let formulaXML = """
<row r="11" spans="1:99" ht="13.15" customHeight="1">
<c r="A11" s="42"/>
<c r="B11" s="42"/>
<c r="C11" s="42" t="s">
<v>42</v>
</c>
<c r="D11" s="42"/>
<c r="E11" s="42"/>
<c r="F11" s="42">
<f ca="1">NOW()</f>
<v>42.42</v>
</c>
<c r="G11" s="363" t="s">
<v>42</v>
</c>
<c r="H11" s="365"/>
<c r="I11" s="96">
<f ca="1">NOW()</f>
<v>42.42</v>
</c>
</row>
""".data(using: .utf8)!

final class FormulaTests: XCTestCase {
private let decoder = XMLDecoder()

func testFormulas() throws {
decoder.shouldProcessNamespaces = true

let row = try decoder.decode(Row.self, from: formulaXML)
XCTAssertEqual(row.cells.count, 9)
XCTAssertEqual(row.cells[5].formula?.value, "NOW()")
XCTAssertEqual(row.cells[8].formula?.value, "NOW()")
}
}
2 changes: 1 addition & 1 deletion Tests/CoreXLSXTests/Namespaces.swift
Expand Up @@ -9,7 +9,7 @@
import XCTest
import XMLCoder

let namespaceXML = """
private let namespaceXML = """
<?xml version="1.0" encoding="utf-8"?>
<x:worksheet \
xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
Expand Down