def table_text_writer(list_input): """Writes table input args: list_input (list of lists): input to be written returns: stream """ from System.IO import StreamWriter, MemoryStream, SeekOrigin list_input = controlled_list(list_input) LOGGER.debug(list_input) LOGGER.debug('--------') header = controlled_list(list_input.pop(0)) length_of_header = len(header) head_line = create_line(header) # if only a header line if not list_input: text = ' ' * (length_of_header) else: text ='' LOGGER.debug('Loop') for i, text_list in enumerate(list_input): text_list = controlled_list(text_list) LOGGER.debug(text_list) if len(text_list) != length_of_header: message = ('Line {} in text: [{}] does not have ' + ' same length as header [{}], will be ' + 'skipped').format(i, join_list(text_list), join_list(header)) ok_message(message) else: text += create_line(text_list) text = head_line + text stream = MemoryStream() writer = StreamWriter(stream) writer.Write(text) writer.Flush() stream.Seek(0, SeekOrigin.Begin) return stream
def csvToDataSource(csv, columnDataTypes): # Create memorystream to read from stream = MemoryStream() writer = StreamWriter(stream) writer.Write(csv) writer.Flush() stream.Seek(0, SeekOrigin.Begin) # Create text file data source readerSettings = TextDataReaderSettings() readerSettings.Separator = ',' readerSettings.AddColumnNameRow(0) print 'columnDataTypes ', columnDataTypes for i, columnDataType in enumerate(columnDataTypes): readerSettings.SetDataType(i, columnDataType) dataSource = TextFileDataSource(stream, readerSettings) dataSource.ReuseSettingsWithoutPrompting = True dataSource.IsPromptingAllowed = False return dataSource
def save_file_dialog(self, sender, event): """open a savefiledialog dialog""" self.save_file_dialog = SaveFileDialog() self.save_file_dialog.InitialDirectory = "%s/winforms" % uiaqa_path self.save_file_dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" self.save_file_dialog.FilterIndex = 2 self.save_file_dialog.RestoreDirectory = True # save the label content to a file. try: if self.save_file_dialog.ShowDialog() == DialogResult.OK: filepath = self.save_file_dialog.FileName s_buf = StreamWriter(filepath) s_buf.Write(self.label.Text) s_buf.Flush() s_buf.Close() self.label.Text = "The path you selected is: " + filepath + '\n' except IOError, event: print 'An error occurred:', event
# Create a web client client = WebClient() # Download the results of that URL results = client.DownloadString("http://localhost:8888/spotfireFramework/assetMarketPlace/customLibs/visTimeline/dxp/eventsGroup.csv") # print these results print results stream = MemoryStream() writer = StreamWriter(stream) writer.Write(results) writer.Flush() stream.Seek(0, SeekOrigin.Begin) readerSettings = TextDataReaderSettings() readerSettings.Separator = "," readerSettings.AddColumnNameRow(0) readerSettings.SetDataType(0, DataType.String) readerSettings.SetDataType(1, DataType.String) readerSettings.SetDataType(2, DataType.DateTime) readerSettings.SetDataType(3, DataType.DateTime) readerSettings.SetDataType(4, DataType.String) readerSettings.SetDataType(5, DataType.String) readerSettings.SetDataType(6, DataType.String) dSource = TextFileDataSource(stream, readerSettings)