def save_to_django_model(self, model, initializer=None, mapdict=None, batch_size=None): """Save to database table through django model :param model: a database model :param initializer: a initialization functions for your model :param mapdict: custom map dictionary for your data columns :param batch_size: a parameter to Django concerning the size for bulk insertion """ save_sheet(self, model=model, initializer=initializer, mapdict=mapdict, batch_size=batch_size)
def save_to_database(self, session, table, initializer=None, mapdict=None, auto_commit=True): """Save data in sheet to database table :param session: database session :param table: a database table :param initializer: a initialization functions for your table :param mapdict: custom map dictionary for your data columns :param auto_commit: by default, data is auto committed. """ save_sheet(self, session=session, table=table, initializer=initializer, mapdict=mapdict, auto_commit=auto_commit)
def save_as(**keywords): """ Save a sheet from a data source to another one """ dest_keywords, source_keywords = _split_keywords(**keywords) sheet_params = {} for field in constants.VALID_SHEET_PARAMETERS: if field in source_keywords: sheet_params[field] = source_keywords.pop(field) sheet_stream = sources.get_sheet_stream(**source_keywords) sheet = Sheet(sheet_stream.payload, sheet_stream.name, **sheet_params) return sources.save_sheet(sheet, **dest_keywords)
def isave_as(**keywords): """ Save a sheet from a data source to another one with less memory It is simliar to :meth:`pyexcel.save_as` except that it does not accept parameters for :class:`pyexcel.Sheet`. And it read when it writes. """ dest_keywords, source_keywords = _split_keywords(**keywords) for field in constants.VALID_SHEET_PARAMETERS: if field in source_keywords: raise Exception(SAVE_AS_EXCEPTION) sheet = sources.get_sheet_stream(on_demand=True, **source_keywords) return sources.save_sheet(sheet, **dest_keywords)
def save_to_memory(self, file_type, stream=None, **keywords): """Save the content to memory :param file_type: any value of 'csv', 'tsv', 'csvz', 'tsvz', 'xls', 'xlsm', 'xlsm', 'ods' :param stream: the memory stream to be written to. Note in Python 3, for csv and tsv format, please pass an instance of StringIO. For xls, xlsx, and ods, an instance of BytesIO. """ stream = save_sheet(self, file_type=file_type, file_stream=stream, **keywords) return stream
def save_as(self, filename, **keywords): """Save the content to a named file Keywords may vary depending on your file type, because the associated file type employs different library. for csv, `fmtparams <https://docs.python.org/release/3.1.5/ library/csv.html#dialects-and-formatting-parameters>`_ are accepted for xls, 'auto_detect_int', 'encoding' and 'style_compression' are supported for ods, 'auto_detect_int' is supported """ return save_sheet(self, file_name=filename, **keywords)
def save_to_memory(self, file_type, stream=None, **keywords): stream = save_sheet(self, file_type=file_type, file_stream=stream, **keywords) return stream
def save_as(self, filename, **keywords): """Save the content to a named file """ return save_sheet(self, file_name=filename, **keywords)
def save_as(**keywords): """Save a sheet from a data source to another one It accepts two sets of keywords. Why two sets? one set is source, the other set is destination. In order to distinguish the two sets, source set will be exactly the same as the ones for :meth:`pyexcel.get_sheet`; destination set are exactly the same as the ones for :class:`pyexcel.Sheet.save_as` but require a 'dest' prefix. :param file_name: a file with supported file extension :param file_content: the file content :param file_stream: the file stream :param file_type: the file type in *content* :param session: database session :param table: database table :param model: a django model :param adict: a dictionary of one dimensional arrays :param url: a download http url for your excel file :param with_keys: load with previous dictionary's keys, default is True :param records: a list of dictionaries that have the same keys :param array: a two dimensional array, a list of lists :param keywords: additional parameters, see :meth:`Sheet.__init__` :param sheet_name: sheet name. if sheet_name is not given, the default sheet at index 0 is loaded :param dest_file_name: another file name. **out_file** is deprecated though is still accepted. :param dest_file_type: this is needed if you want to save to memory :param dest_session: the target database session :param dest_table: the target destination table :param dest_model: the target django model :param dest_mapdict: a mapping dictionary, see :meth:`pyexcel.Sheet.save_to_memory` :param dest_initializer: a custom initializer function for table or model :param dest_mapdict: nominate headers :param dest_batch_size: object creation batch size. it is Django specific :returns: IO stream if saving to memory. None otherwise if csv file is destination format, python csv `fmtparams <https://docs.python.org/release/3.1.5/ library/csv.html#dialects-and-formatting-parameters>`_ are accepted for example: dest_lineterminator will replace default '\r\n' to the one you specified ========================== ========================================= source parameters ========================== ========================================= loading from file file_name, sheet_name, keywords loading from string file_content, file_type, sheet_name, keywords loading from stream file_stream, file_type, sheet_name, keywords loading from sql session, table loading from sql in django model loading from query sets any query sets(sqlalchemy or django) loading from dictionary adict, with_keys loading from records records loading from array array loading from an url url ========================== ========================================= ================= ============================================= Saving to source parameters ================= ============================================= file dest_file_name, dest_sheet_name, keywords with prefix 'dest' memory dest_file_type, dest_content, dest_sheet_name, keywords with prefix 'dest' sql dest_session, dest_table, dest_initializer, dest_mapdict django model dest_model, dest_initializer, dest_mapdict, dest_batch_size ================= ============================================= In addition, this function use :class:`pyexcel.Sheet` to render the data which could have performance penalty. In exchange, parameters for :class:`pyexcel.Sheet` can be passed on, e.g. `name_columns_by_row`. """ dest_keywords, source_keywords = _split_keywords(**keywords) sheet_params = {} for field in constants.VALID_SHEET_PARAMETERS: if field in source_keywords: sheet_params[field] = source_keywords.pop(field) sheet_stream = sources.get_sheet_stream(**source_keywords) sheet = Sheet(sheet_stream.payload, sheet_stream.name, **sheet_params) return sources.save_sheet(sheet, **dest_keywords)