Check out the export of data to Excel

Check out the export of data to Excel

文献种类:专题技术文献;
开发工具与关键技术:VS
作者:蛋蛋;
撰写时间:2019/06/6

What is exported?
Literally means is to be appreciated, the guide: a guide, a: and out process,
so it is exported to guide out the data transferred to another storage procedure. Export to Excel spreadsheet first need to be a few steps,
first: the rendering table data out;
second: screened so we need to export data according to operating conditions based on demand, will render tabular data out,
Here Insert Picture Description
see what needs to look you need to analyze how to go check out the required fields to meet demand, it is clearly out of the multi-table query data.
Arranging table respectively as the primary table, listing table as a foreign key to another table is connected, as well as the state table
(Table considering the state of the project multiple phases so built an enumeration class, also known is the state table )
in a filter condition is, from the figure we see three input filter by label the entire data also advanced queries
, of which there are screening time as one of the conditions
of the second: these filter criteria are equally indispensable to do before exporting less conditions, depending on the required export data
before writing method ① to export the click event to write, οnclick = "ExportToExcel ()" plus remember () because it always like this at the same time also made a stupid mistake, and then not being given the same time not start breakpoints check for errors, try to check the blind JS code causes the loss of time,
② obtain current filter tabular data (advanced Search)
③ prompt the user to print to an Excel spreadsheet, improve the user experience in case of delays can reduce unnecessary trouble
var index = layer.confirm ( "Do you want to export the data in the current form, it is please click the OK button, otherwise sieve ! Need to export data ", {icon: 3, title :" prompt "}, function () {
// Close the modal box layer.close (index);
 window.open ( "ExportToExcel RegisterOdd =?" + RegisterOdd + "& ClientName =" + ClientName + "& RowNumberTime =" + RowNumberTime); window.open means is opened,
 the rear side of the main conditions for the controller to slightly complicated splicing a little bit, but to understand them is not particularly about the first check out the data we need with the start we render the table when this is the same so you can directly use Note:
 export Excel spreadsheet need to introduce a new thing NPOI
Here Insert Picture Description
when reference is also very simple , first copy the files to the project folder with them, quote directly add a reference to open the "view" among [solution Explorer] is
Here Insert Picture Description
found browsing recently added directly into the folder to see them on the introduction of file OK after you need to make the corresponding Excel spreadsheet format

  1. Create an Excel workbook HSSFWorkbook excelBook = new HSSFWorkbook (); create a new workbook
  2. Create a worksheet NPOI.SS.UserModel.ISheet sheet1 = excelBook.CreateSheet ( "Sales Management - Arranging query"); it is an Excel worksheet will appear at the bottom, followed by the file name (custom)
  3. Here Insert Picture Description
  4. Create a header row NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow (0);
  5. Set header row1.CreateCell (0) .SetCellValue ( "Registration No. mono"); row1.CreateCell (1) .SetCellValue ( "Customer Name"); row1.CreateCell (2) .SetCellValue ( "BAN"); row1 .CreateCell (3) .SetCellValue ( "room number");
  6. row1.CreateCell (4) .SetCellValue ( "rank number"); row1.CreateCell (5) .SetCellValue ( "document date"); row1.CreateCell (6) .SetCellValue ( "state");
  7. This is beginning to create a query based on the header data out
  8. Adding data to an Excel spreadsheet using a for loop, because there may be more than one data he has a lot of bars,
  9. for (int i = 0; i < listLineNumber.Count(); i++){ //创建行NPOI.SS.UserModel.IRow rowTemp = sheet1.CreateRow(i + 1);
  10. // add data rowTemp.CreateCell (0) .SetCellValue (listLineNumber [i] .RegisterOdd); // single registration number rowTemp.CreateCell (1) .SetCellValue (listLineNumber [i] .ClientName); // Name},

Because the project needs six field means that there are six tables need to add header and six data so when added to so

  1. Next is the file name string fileName = "Sales Management - Arranging query" + DateTime.Now.ToString ( "yyy-MM -dd-HH-mm-ss-ffff") + ".xls";
    followed by print time time: year / month / day / hour / minute / second and folders suffix;
    and final step to convert the file into memory stream MemoryStream ExcelStream = new MemoryStream (); will be written to the memory stream Excel file, excelBook.Write (ExcelStream) ; // output before calling Seek (offsets, the cursor position) to read the file pointer to a specified location // Seek (0, Seek, begin )
    a first parameter indicates a relative position, the reference position is the second
    ExcelStream.Seek (0, SeekOrigin.Begin); // MIME file types (multipurpose Internet Mail extensions) multipurpose Internet Mail extensions type return file (ExcelStream, "application / vnd.ms-excel", fileName); so export to Excel spreadsheet is complete a look at the final image
    Here Insert Picture Description
    should do it but there is a useless filter criteria with advanced query conditions as constraints that will happen then? Here Insert Picture Description
    This is the time of screening as a condition
    Here Insert Picture Description
    of such exported to an Excel spreadsheet is complete
    Here Insert Picture Description
    which is the file name and file storage time suffix etc.

Guess you like

Origin blog.csdn.net/qq_42577408/article/details/91128437