# Path: openpyxl/writer/strings.py
# class StringTableBuilder(object):
# 
#     def __init__(self):
# 
#         self.counter = 0
#         self.dct = {}
# 
#     def add(self, key):
# 
#         key = key.strip()
#         try:
#             return self.dct[key]
#         except KeyError:
#             res = self.dct[key] = self.counter
#             self.counter += 1
#             return res
# 
#     def get_table(self):
# 
#         return self.dct
# 
# Path: openpyxl/style.py
# class Style(HashableObject):
#     """Style object containing all formatting details."""
#     __fields__ = ('font',
#                   'fill',
#                   'borders',
#                   'alignment',
#                   'number_format',
#                   'protection')
#     __slots__ = __fields__
# 
#     def __init__(self):
#         super(Style, self).__init__()
#         self.font = Font()
#         self.fill = Fill()
#         self.borders = Borders()
#         self.alignment = Alignment()
#         self.number_format = NumberFormat()
#         self.protection = Protection()
# 
# Path: openpyxl/writer/excel.py
# def save_workbook(workbook, filename):
#     """Save the given workbook on the filesystem under the name filename.
# 
#     :param workbook: the workbook to save
#     :type workbook: :class:`openpyxl.workbook.Workbook`
# 
#     :param filename: the path to which save the workbook
#     :type filename: string
# 
#     :rtype: bool
# 
#     """
#     writer = ExcelWriter(workbook)
#     writer.save(filename)
#     return True


import datetime
import os
from openpyxl.worksheet import Worksheet
from openpyxl.writer.dump_worksheet import DumpWorksheet, save_dump
from openpyxl.writer.strings import StringTableBuilder
from openpyxl.namedrange import NamedRange
from openpyxl.style import Style
from openpyxl.writer.excel import save_workbook
from openpyxl.shared.exc import ReadOnlyWorkbookException
        assert isinstance(worksheet, Worksheet)
        named_range = NamedRange(name, [(worksheet, range)])
        self.add_named_range(named_range)

    def get_named_ranges(self):
        """Return all named ranges"""
        return self._named_ranges

    def add_named_range(self, named_range):
        """Add an existing named_range to the list of named_ranges."""
        self._named_ranges.append(named_range)

    def get_named_range(self, name):
        """Return the range specified by name."""
        requested_range = None
        for named_range in self._named_ranges:
            if named_range.name == name:
                requested_range = named_range
                break
        return requested_range

    def remove_named_range(self, named_range):
        """Remove a named_range from this workbook."""
        self._named_ranges.remove(named_range)

    def save(self, filename):
        """ shortcut """
        if self.__optimized_write:
            save_dump(self, filename)
        else:

# Path: openpyxl/writer/strings.py
# class StringTableBuilder(object):
# 
#     def __init__(self):
# 
#         self.counter = 0
#         self.dct = {}
# 
#     def add(self, key):
# 
#         key = key.strip()
#         try:
#             return self.dct[key]
#         except KeyError:
#             res = self.dct[key] = self.counter
#             self.counter += 1
#             return res
# 
#     def get_table(self):
# 
#         return self.dct
# 
# Path: openpyxl/style.py
# class Style(HashableObject):
#     """Style object containing all formatting details."""
#     __fields__ = ('font',
#                   'fill',
#                   'borders',
#                   'alignment',
#                   'number_format',
#                   'protection')
#     __slots__ = __fields__
# 
#     def __init__(self):
#         super(Style, self).__init__()
#         self.font = Font()
#         self.fill = Fill()
#         self.borders = Borders()
#         self.alignment = Alignment()
#         self.number_format = NumberFormat()
#         self.protection = Protection()
# 
# Path: openpyxl/writer/excel.py
# def save_workbook(workbook, filename):
#     """Save the given workbook on the filesystem under the name filename.
# 
#     :param workbook: the workbook to save
#     :type workbook: :class:`openpyxl.workbook.Workbook`
# 
#     :param filename: the path to which save the workbook
#     :type filename: string
# 
#     :rtype: bool
# 
#     """
#     writer = ExcelWriter(workbook)
#     writer.save(filename)
#     return True


# Path: openpyxl/workbook.py
import datetime
import os
from openpyxl.worksheet import Worksheet
from openpyxl.writer.dump_worksheet import DumpWorksheet, save_dump
from openpyxl.writer.strings import StringTableBuilder
from openpyxl.namedrange import NamedRange
from openpyxl.style import Style
from openpyxl.writer.excel import save_workbook
from openpyxl.shared.exc import ReadOnlyWorkbookException

        assert isinstance(worksheet, Worksheet)
        named_range = NamedRange(name, [(worksheet, range)])
        self.add_named_range(named_range)

    def get_named_ranges(self):
        """Return all named ranges"""
        return self._named_ranges

    def add_named_range(self, named_range):
        """Add an existing named_range to the list of named_ranges."""
        self._named_ranges.append(named_range)

    def get_named_range(self, name):
        """Return the range specified by name."""
        requested_range = None
        for named_range in self._named_ranges:
            if named_range.name == name:
                requested_range = named_range
                break
        return requested_range

    def remove_named_range(self, named_range):
        """Remove a named_range from this workbook."""
        self._named_ranges.remove(named_range)

    def save(self, filename):
        """ shortcut """
        if self.__optimized_write:
            save_dump(self, filename)
        else:

            save_workbook(self, filename)