public IActionResult Batchs(string command, string ids) { var response = ResponseModelFactory.CreateInstance; string sWebRootFolder = _hostingEnvironment.WebRootPath + "\\UploadFiles\\ImportUserInfoWord\\"; var timeInfo = DateTime.Now.ToString("yyyyMMddHHmmss"); var wordName = timeInfo + "address.docx"; string wordUrl = sWebRootFolder + wordName; MemoryStream ms = new MemoryStream(); XWPFDocument m_Docx = new XWPFDocument(); m_Docx.Write(ms); ms.Flush(); SaveToFile(ms, wordUrl); List <string> list = new List <string>(); using (_dbContext) { //document111.LoadFromFile(sWebRootFolder + "test.docx"); Document document111 = new Document(); document111.LoadFromFile(wordUrl); Section section = document111.Sections[0]; document111.Watermark = null; section.Paragraphs[0].AppendBookmarkStart("picture"); section.Paragraphs[0].AppendBookmarkEnd("picture"); var parameters = ids.Split(",").Select((id, index) => new SqlParameter(string.Format("@p{0}", index), id)).ToList(); var parameterNames = string.Join(", ", parameters.Select(p => p.ParameterName)); var entities = _dbContext.GrabageRoom.Where(x => ids.IndexOf(x.GarbageRoomUuid.ToString()) >= 0).ToList(); for (int i = 0; i < entities.Count; i++) { var pata = _hostingEnvironment.WebRootPath + EWM.GetEWM2("d_" + entities[i].GarbageRoomUuid.ToString(), _hostingEnvironment, entities[i].Ljname); //实例化BookmarksNavigator类,指定需要添加图片的书签“” BookmarksNavigator bn = new BookmarksNavigator(document111); bn.MoveToBookmark("picture", true, true); //添加段落,加载图片并插入到段落 Section section0 = document111.AddSection(); Spire.Doc.Documents.Paragraph paragraph = section0.AddParagraph(); Image image = Image.FromFile(pata); //DocPicture picture = paragraph.AppendPicture(image); DocPicture picture = document111.Sections[0].Paragraphs[0].AppendPicture(image); picture.Width = 160; picture.Height = 180; //picture.HorizontalPosition = 100.0f; //picture.VerticalPosition = 100.0f; bn.InsertParagraph(paragraph); document111.Sections.Remove(section0); //string output = sWebRootFolder + "test.docx"; document111.SaveToFile(wordUrl, FileFormat.Docx); } list.Add(wordUrl); //关闭进程 document111.Dispose(); var time = DateTime.Now.ToString("yyyyMMddHHmmssfff"); var check = ZIP.CompressMulti(list, _hostingEnvironment.WebRootPath + "\\UploadFiles\\EWM\\" + time, false); if (check) { response.SetSuccess("导出成功"); response.SetData("\\UploadFiles\\EWM\\" + time + ".zip"); } else { response.SetFailed("导出失败"); } return(Ok(response)); } }
public IActionResult yjExportInfo(AddressRequestPayload payload) { var response = ResponseModelFactory.CreateInstance; string sWebRootFolder = _hostingEnvironment.WebRootPath + "\\UploadFiles\\ImportUserInfoWord\\"; var timeInfo = DateTime.Now.ToString("yyyyMMddHHmmss"); var wordName = timeInfo + "address.docx"; string wordUrl = sWebRootFolder + wordName; MemoryStream ms = new MemoryStream(); XWPFDocument m_Docx = new XWPFDocument(); m_Docx.Write(ms); ms.Flush(); SaveToFile(ms, wordUrl); List <string> list = new List <string>(); using (_dbContext) { Document document111 = new Document(); document111.LoadFromFile(wordUrl); Section section = document111.Sections[0]; section.Paragraphs[0].AppendBookmarkStart("picture"); section.Paragraphs[0].AppendBookmarkEnd("picture"); var user = AuthContextService.CurrentUser; string s1 = payload.Kw2; string[] s2 = s1.Split(" "); StringBuilder where = new StringBuilder(); StringBuilder sql = new StringBuilder("SELECT * FROM HomeAddress HA "); for (int i = 0; i < s2.Length; i++) { if (s2.Length > 0 && i == 0) { where.Append("WHERE "); } where.Append("HA.Address LIKE '%" + s2[i] + "%' "); if (i >= 0 && i < s2.Length - 1) { where.Append(" AND "); } } sql.Append(where); //var query = _dbContext.HomeAdd.FromSql(sql.ToString()); var query = _dbContext.HomeAddress.FromSqlRaw(sql.ToString()); if (!string.IsNullOrEmpty(payload.Kw)) { query = query.Where(x => x.Address.ToString().Contains(payload.Kw)); } if (!string.IsNullOrEmpty(payload.Kw1)) { query = query.Where(x => x.Address.ToString().Contains(payload.Kw1)); } var entities = query.ToList(); //var entities = _dbContext.HomeAddress.Where(x => ids.IndexOf(x.HomeAddressUuid.ToString()) >= 0).ToList(); for (int i = 0; i < entities.Count(); i++) { var pata = _hostingEnvironment.WebRootPath + EWM.GetEWM2("h_" + entities[i].HomeAddressUuid.ToString(), _hostingEnvironment, entities[i].Address); //实例化BookmarksNavigator类,指定需要添加图片的书签“” BookmarksNavigator bn = new BookmarksNavigator(document111); bn.MoveToBookmark("picture", true, true); //添加段落,加载图片并插入到段落 Section section0 = document111.AddSection(); Spire.Doc.Documents.Paragraph paragraph = section0.AddParagraph(); Image image = Image.FromFile(pata); DocPicture picture = document111.Sections[0].Paragraphs[0].AppendPicture(image); picture.Width = 160; picture.Height = 180; //picture.HorizontalPosition = 100.0f; //picture.VerticalPosition = 50.0f; bn.InsertParagraph(paragraph); document111.Sections.Remove(section0); //string output = sWebRootFolder + "test.docx"; document111.SaveToFile(wordUrl, FileFormat.Docx); //Arraypata = pata.; //list.Add(pata); } list.Add(wordUrl); //关闭进程 document111.Dispose(); var time = DateTime.Now.ToString("yyyyMMddHHmmssfff"); var check = ZIP.CompressMulti(list, _hostingEnvironment.WebRootPath + "\\UploadFiles\\EWM\\" + time, false); if (check) { response.SetSuccess("导出成功"); response.SetData("\\UploadFiles\\EWM\\" + time + ".zip"); } else { response.SetFailed("导出失败"); } } return(Ok(response)); }