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

Method workSheetReader

excelize.go:282–327  ·  view source on GitHub ↗

workSheetReader provides a function to get the pointer to the structure after deserialization by given worksheet name.

(sheet string)

Source from the content-addressed store, hash-verified

280// workSheetReader provides a function to get the pointer to the structure
281// after deserialization by given worksheet name.
282func (f *File) workSheetReader(sheet string) (ws *xlsxWorksheet, err error) {
283 var (
284 name string
285 ok bool
286 )
287 if err = checkSheetName(sheet); err != nil {
288 return
289 }
290 if name, ok = f.getSheetXMLPath(sheet); !ok {
291 err = ErrSheetNotExist{sheet}
292 return
293 }
294 if worksheet, ok := f.Sheet.Load(name); ok && worksheet != nil {
295 ws = worksheet.(*xlsxWorksheet)
296 return
297 }
298 for _, sheetType := range []string{"xl/chartsheets", "xl/dialogsheet", "xl/macrosheet"} {
299 if strings.HasPrefix(name, sheetType) {
300 err = newNotWorksheetError(sheet)
301 return
302 }
303 }
304 ws = new(xlsxWorksheet)
305 if attrs, ok := f.xmlAttr.Load(name); !ok {
306 d := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readBytes(name))))
307 if attrs == nil {
308 attrs = []xml.Attr{}
309 }
310 attrs = append(attrs.([]xml.Attr), getRootElement(d)...)
311 f.xmlAttr.Store(name, attrs)
312 }
313 if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readBytes(name)))).
314 Decode(ws); err != nil && err != io.EOF {
315 return
316 }
317 err = nil
318 if _, ok = f.checked.Load(name); !ok {
319 ws.checkSheet()
320 if err = ws.checkRow(); err != nil {
321 return
322 }
323 f.checked.Store(name, true)
324 }
325 f.Sheet.Store(name, ws)
326 return
327}
328
329// checkSheet provides a function to fill each row element and make that is
330// continuous in a worksheet of XML.

Callers 15

TestSetConditionalFormatFunction · 0.95
setCellTimeFuncMethod · 0.95
SetCellIntMethod · 0.95
SetCellUintMethod · 0.95
SetCellBoolMethod · 0.95
SetCellFloatMethod · 0.95
SetCellStrMethod · 0.95
SetCellDefaultMethod · 0.95
SetCellFormulaMethod · 0.95
setArrayFormulaCellsMethod · 0.95

Calls 9

getSheetXMLPathMethod · 0.95
xmlNewDecoderMethod · 0.95
readBytesMethod · 0.95
checkSheetNameFunction · 0.85
newNotWorksheetErrorFunction · 0.85
getRootElementFunction · 0.85
checkSheetMethod · 0.80
checkRowMethod · 0.80

Tested by 15

TestSetConditionalFormatFunction · 0.76
TestAppendSparklineFunction · 0.76
TestRemoveRowFunction · 0.76
TestInsertRowsFunction · 0.76
TestProtectSheetFunction · 0.76
TestWorkSheetReaderFunction · 0.76
TestAdjustColDimensionsFunction · 0.76
TestAdjustRowDimensionsFunction · 0.76
TestAdjustHyperlinksFunction · 0.76