Home > Back-end >  Visual Studio
Visual Studio

Time:12-04

1 export
Excel data processing function is very powerful, so in daily work, we often need to wait for data from the database or the Datatable data imported into Excel document for data analysis or operations, sometimes need to Excel in the document or the Datatable to read data, export data to database
Export Excel file one train of thought is the WPF data display control (such as DataGrid) into memory built in Excel file, and then through the save file dialog box choose save the file path, to save memory in Excel file to choose the path;
Step 1: specify the virtual path corresponding physical template file paths, check the Excel, workbook and the existence of the worksheet and

Step 2: declare two strings and instantiate the common dialog box (get or set the filter string, used to determine the open file dialog box displays the file type), and (in the open file dialog box to select a single file, containing the full path),
Step 3: get exported data screening, cite NPOI to read data

Step 4: using NPOI open template Excel, using FileStream (using the specified read/write permissions for the specified File handle initialization System. IO. FileStream new instance of the class, File: used to create, copy, delete, move and static methods, open the File and help to create System. IO. FileStream object,) File open Excel template File, get a workbook (HSSFWorkbook excelBookTemplate: through NPOI access to upload are transformed from an Excel spreadsheet workbook), open the Excel template files in the first worksheet, constructs the cell style, and set the title, if the screening period isn't empty screen time on joining together

Using NPOI read data, obtaining template file format add data circulation in the header row each value in the cell, cell of imported into Excel,
(MemoryStream: create its support for storage area for memory stream,) define the Excel into document flow, flow of thin and work will be written to the File, the output before calling the Seek method (offset, the cursor position) : to obtain the length of the File stream will Excel through the File stream (File) to return to the view

2 the import
Excel data processing function is very powerful, so in daily work, we often need to wait for data from the database or the Datatable data imported into Excel document for data analysis or operations, sometimes need to Excel in the document or the Datatable to read data, export data to database
Export Excel file one train of thought is the WPF data display control (such as DataGrid) into memory built in Excel file, and then through the save file dialog box choose save the file path, to save memory in Excel file to choose the path;
Step 1: specify the virtual path corresponding physical template file paths, check the Excel, workbook and the existence of the worksheet and

Step 2: statement string and instantiate common dialog box (get or set the filter string, used to determine the open file dialog box displays the file type), and (in the open file dialog box to select a single file, containing the full path),
Step 3: you need to import the data files, references to NPOI to read data:


Step 4: the file is converted into a binary array, binary array into the memory flow, using NPOI to read the memory stream data into Excel, to determine whether there is data in the worksheet, then keep the Excel to the temporary table inside () in the DataTable, obtaining template file format,
Using NPOI read data, add data circulation in the header row each value in the cell, imported into the worksheet cell,
Step 5: after passing data, and transfer data to determine whether complete, give users to set some hints, defined in the controller a method to receive and view the data, in method to instantiate the data, in the assignment of it after the assignment, is imported, finished, save the data to determine whether the data import is successful, the data is null/whether the data according to the template to fill in,


(3) to upload pictures
Set the ID and click on the name of the event, setting image shows long and high

Set the format of the picture, make it can be submitted through the file upload file type
The accept attribute only with & lt; Input type="file" & gt; Cooperate to use

Set the picture double-click events, use jqury triggers the click event of file option box & lt; Input type="file" & gt;

The custom user avatar click event, view your avatar picture information, according to whether there is a head picture information view/not upload

Click the view button to display images, according to the events will leave the image path, click on the button to play window layer shows images information content, don't open the title, is not set up the close button, can be directly click on the mask layer close the pop-up window,

With image file of the regular expression filter cannot read the file picture format, display can select image files, will choose picture to ing elements, and use the FileReader reads the images into a URL, use file read the onl oad event, will read the pictures showed to ing element

Popup window modified modal form set shows the location of the user avatar and image path
Keep head is modify the user information, first of all get the user avatar parameter, use the JQuery Ajax send FormData data, build the FormData data, data submitted to the controller, to tell JQuery don't sent to deal with data and don't set the content-type request header


Query before avatar picture information, see whether to upload the image, set the file type (Path: contains information about a file or directory Path System. String instance execution) (GetExtension: the specified Path String extensions) return Path to receive files
Save the file path and server deployment path, set the file name to the user, before the judgment whether there was a picture before, you need to remove the old image information, to upload pictures don't do any deal with the images in the database directly set hair oh the user object,