modules/cij/xlsx.py
def import_source(self, sheet, source, delimiter=","):
        """
        Function:
            Save original data into specific sheet, and try to translate data to float type
        Input:
            sheet: Must be a non exists sheet
            source: File path of source
        """
        # check input parameters
        if ' ' in sheet:
            raise RuntimeError("Error sheet name: %s" % sheet)

        if not source.endswith("txt") and not source.endswith("csv"):
            raise RuntimeError("Error source name: %s" % source)

        self.source_sheet = sheet

        source_data = np.loadtxt(source, dtype=str, delimiter=delimiter)
        self.source_data = {"title": source_data[0].tolist(),
                            "data": source_data[1:]}

        cell_format_title = self.workbook.add_format({'bold': True,
                                                      'font_name': u'等线',
                                                      'bg_color': '#c5d9f1',
                                                      'rotation': 45})
        cell_format = self.workbook.add_format({'bold': False,
                                                'font_name': u'等线',
                                                'num_format': 0})

        worksheet = self.workbook.add_worksheet(sheet)
        worksheet.write_row('A1', self.source_data['title'], cell_format_title)

        _, col_num = self.source_data['data'].shape
        for i in range(col_num):
            try:
                data_array = self.source_data['data'][:, i].astype(float)
            except ValueError:
                data_array = self.source_data['data'][:, i]

            worksheet.write_column(1, i, data_array.tolist(), cell_format)
def import_source(self, sheet, source, delimiter=","):
        """
        Function:
            Save original data into specific sheet, and try to translate data to float type
        Input:
            sheet: Must be a non exists sheet
            source: File path of source
        """
        # check input parameters
        if ' ' in sheet:
            raise RuntimeError("Error sheet name: %s" % sheet)

        if not source.endswith("txt") and not source.endswith("csv"):
            raise RuntimeError("Error source name: %s" % source)

        self.source_sheet = sheet

        source_data = np.loadtxt(source, dtype=str, delimiter=delimiter)
        self.source_data = {"title": source_data[0].tolist(),
                            "data": source_data[1:]}

        cell_format_title = self.workbook.add_format({'bold': True,
                                                      'font_name': u'等线',
                                                      'bg_color': '#c5d9f1',
                                                      'rotation': 45})
        cell_format = self.workbook.add_format({'bold': False,
                                                'font_name': u'等线',
                                                'num_format': 0})

        worksheet = self.workbook.add_worksheet(sheet)
        worksheet.write_row('A1', self.source_data['title'], cell_format_title)

        _, col_num = self.source_data['data'].shape
        for i in range(col_num):
            try:
                data_array = self.source_data['data'][:, i].astype(float)
            except ValueError:
                data_array = self.source_data['data'][:, i]

            worksheet.write_column(1, i, data_array.tolist(), cell_format)
Function:
            Save original data into specific sheet, and try to translate data to float type
        Input:
            sheet: Must be a non exists sheet
            source: File path of source