• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xlnt-community / xlnt / 2fb57988-1891-456a-9f50-ba8202ac9608

27 Jan 2026 07:00AM UTC coverage: 83.928% (+1.1%) from 82.793%
2fb57988-1891-456a-9f50-ba8202ac9608

Pull #87

circleci

doomlaur
Slightly clarified character encodings in README.md
Pull Request #87: Improve documentation when exceptions are thrown (fixes #81)

15263 of 19954 branches covered (76.49%)

722 of 901 new or added lines in 37 files covered. (80.13%)

15 existing lines in 5 files now uncovered.

12491 of 14883 relevant lines covered (83.93%)

12216.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.38
./source/workbook/streaming_workbook_reader.cpp
1
// Copyright (c) 2017-2022 Thomas Fussell
2
// Copyright (c) 2024-2025 xlnt-community
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a copy
5
// of this software and associated documentation files (the "Software"), to deal
6
// in the Software without restriction, including without limitation the rights
7
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
// copies of the Software, and to permit persons to whom the Software is
9
// furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
// THE SOFTWARE
21
//
22
// @license: http://www.opensource.org/licenses/mit-license.php
23
// @author: see AUTHORS file
24

25
#include <fstream>
26

27
#include <xlnt/cell/cell.hpp>
28
#include <xlnt/packaging/manifest.hpp>
29
#include <xlnt/utils/optional.hpp>
30
#include <xlnt/workbook/streaming_workbook_reader.hpp>
31
#include <xlnt/workbook/workbook.hpp>
32
#include <xlnt/worksheet/worksheet.hpp>
33
#include <detail/implementations/workbook_impl.hpp>
34
#include <detail/serialization/open_stream.hpp>
35
#include <detail/serialization/vector_streambuf.hpp>
36
#include <detail/serialization/xlsx_consumer.hpp>
37

38
namespace xlnt {
39

40
streaming_workbook_reader::streaming_workbook_reader()
3✔
41
{
42
}
3✔
43

44
streaming_workbook_reader::~streaming_workbook_reader()
3✔
45
{
46
    close();
3✔
47
}
3✔
48

49
void streaming_workbook_reader::close()
3✔
50
{
51
    if (consumer_)
3!
52
    {
53
        consumer_.reset(nullptr);
3✔
54
        stream_buffer_.reset(nullptr);
3✔
55
    }
56
}
3✔
57

58
bool streaming_workbook_reader::has_cell()
155✔
59
{
60
    return consumer_->has_cell();
155✔
61
}
62

63
cell streaming_workbook_reader::read_cell()
153✔
64
{
65
    return consumer_->read_cell();
153✔
66
}
67

68
bool streaming_workbook_reader::has_worksheet(const std::string &name)
4✔
69
{
70
    auto titles = sheet_titles();
4✔
71
    return std::find(titles.begin(), titles.end(), name) != titles.end();
8✔
72
}
4✔
73

74
void streaming_workbook_reader::begin_worksheet(const std::string &title)
4✔
75
{
76
    if (!has_worksheet(title))
4✔
77
    {
78
        throw xlnt::key_not_found(title);
1✔
79
    }
80

81
    worksheet_rel_id_ = workbook_->impl().sheet_title_rel_id_map_.at(title);
3✔
82
    const auto workbook_rel = workbook_->manifest()
3✔
83
                                  .relationship(path("/"), relationship_type::office_document);
3✔
84
    const auto worksheet_rel = workbook_->manifest()
3✔
85
                                   .relationship(workbook_rel.target().path(), worksheet_rel_id_);
3✔
86

87
    auto rel_chain = std::vector<relationship>{workbook_rel, worksheet_rel};
12!
88

89
    const auto &manifest = consumer_->target_.manifest();
3✔
90
    const auto part_path = manifest.canonicalize(rel_chain);
3✔
91
    auto part_stream_buffer = consumer_->archive_->open(part_path);
3✔
92
    part_stream_buffer_.swap(part_stream_buffer);
3✔
93
    part_stream_.reset(new std::istream(part_stream_buffer_.get()));
3!
94
    parser_.reset(new xml::parser(*part_stream_, part_path.string()));
3!
95
    consumer_->parser_ = parser_.get();
3✔
96

97
    consumer_->current_worksheet_ = nullptr;
3✔
98

99
    for (auto &impl : workbook_->impl().worksheets_)
6✔
100
    {
101
        if (impl.title_ == title)
3!
102
        {
103
            consumer_->current_worksheet_ = &impl;
3✔
104
        }
105
    }
106

107
    if (consumer_->current_worksheet_ == nullptr)
3!
108
    {
NEW
109
        throw xlnt::key_not_found(title);
×
110
    }
111

112
    consumer_->read_worksheet_begin(worksheet_rel_id_);
3✔
113
}
6!
114

115
worksheet streaming_workbook_reader::end_worksheet()
1✔
116
{
117
    return consumer_->read_worksheet_end(worksheet_rel_id_);
1✔
118
}
119

120
void streaming_workbook_reader::open(const std::vector<std::uint8_t> &data)
×
121
{
122
    stream_buffer_.reset(new detail::vector_istreambuf(data));
×
123
    stream_.reset(new std::istream(stream_buffer_.get()));
×
124
    open(*stream_);
×
125
}
×
126

127
void streaming_workbook_reader::open(const std::string &filename)
×
128
{
129
    stream_.reset(new std::ifstream());
×
130
    xlnt::detail::open_stream(static_cast<std::ifstream &>(*stream_), filename);
×
131
    open(*stream_);
×
132
}
×
133

134
#ifdef _MSC_VER
135
void streaming_workbook_reader::open(const std::wstring &filename)
136
{
137
    stream_.reset(new std::ifstream());
138
    xlnt::detail::open_stream(static_cast<std::ifstream &>(*stream_), filename);
139
    open(*stream_);
140
}
141
#endif
142

143
void streaming_workbook_reader::open(const xlnt::path &filename)
3✔
144
{
145
    stream_.reset(new std::ifstream());
3!
146
    xlnt::detail::open_stream(static_cast<std::ifstream &>(*stream_), filename.string());
3✔
147
    open(*stream_);
3✔
148
}
3✔
149

150
void streaming_workbook_reader::open(std::istream &stream)
3✔
151
{
152
    workbook_.reset(new workbook());
3!
153
    consumer_.reset(new detail::xlsx_consumer(*workbook_));
3!
154
    consumer_->open(stream);
3✔
155

156
    const auto workbook_rel = workbook_->manifest()
3✔
157
                                  .relationship(path("/"), relationship_type::office_document);
3✔
158
    const auto workbook_path = workbook_rel.target().path();
3✔
159
}
3✔
160

161
void streaming_workbook_reader::open(std::unique_ptr<std::streambuf> &&buffer)
×
162
{
163
    stream_buffer_.swap(buffer);
×
164
    stream_.reset(new std::istream(stream_buffer_.get()));
×
165
    open(*stream_);
×
166
}
×
167

168
std::vector<std::string> streaming_workbook_reader::sheet_titles()
5✔
169
{
170
    return workbook_->sheet_titles();
5✔
171
}
172

173
} // namespace xlnt
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc