MCPcopy
hub / github.com/qax-os/excelize / GetTables

Method GetTables

table.go:129–169  ·  view source on GitHub ↗

GetTables provides the method to get all tables in a worksheet by given worksheet name.

(sheet string)

Source from the content-addressed store, hash-verified

127// GetTables provides the method to get all tables in a worksheet by given
128// worksheet name.
129func (f *File) GetTables(sheet string) ([]Table, error) {
130 var tables []Table
131 ws, err := f.workSheetReader(sheet)
132 if err != nil {
133 return tables, err
134 }
135 if ws.TableParts == nil {
136 return tables, err
137 }
138 for _, tbl := range ws.TableParts.TableParts {
139 if tbl != nil {
140 target := f.getSheetRelationshipsTargetByID(sheet, tbl.RID)
141 tableXML := strings.ReplaceAll(target, "..", "xl")
142 content, ok := f.Pkg.Load(tableXML)
143 if !ok {
144 continue
145 }
146 var t xlsxTable
147 if err := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(content.([]byte)))).
148 Decode(&t); err != nil && err != io.EOF {
149 return tables, err
150 }
151 table := Table{
152 rID: tbl.RID,
153 tID: t.ID,
154 tableXML: tableXML,
155 Range: t.Ref,
156 Name: t.Name,
157 }
158 if t.TableStyleInfo != nil {
159 table.StyleName = t.TableStyleInfo.Name
160 table.ShowColumnStripes = t.TableStyleInfo.ShowColumnStripes
161 table.ShowFirstColumn = t.TableStyleInfo.ShowFirstColumn
162 table.ShowLastColumn = t.TableStyleInfo.ShowLastColumn
163 table.ShowRowStripes = &t.TableStyleInfo.ShowRowStripes
164 }
165 tables = append(tables, table)
166 }
167 }
168 return tables, err
169}
170
171// DeleteTable provides the method to delete table by given table name.
172func (f *File) DeleteTable(name string) error {

Callers 4

TestGetTablesFunction · 0.95
getSlicerSourceMethod · 0.95
getTablesMethod · 0.95
TestAddTableFunction · 0.80

Calls 4

workSheetReaderMethod · 0.95
xmlNewDecoderMethod · 0.95

Tested by 2

TestGetTablesFunction · 0.76
TestAddTableFunction · 0.64