『壹』 CAD圖紙打開後用defpoits圖層標注後保存在哪裡
當您通過CAD軟體打開一份圖紙並使用defpoints圖層進行標注後,保存文件時應該將其保存為原始文件的修改版本或者另存為一個新的文件。您可以按照以下步驟進行操作:
點擊CAD軟體菜單欄中的「文件」選項。
選擇「另存為」或者「存儲」選項。
選擇您要保存的位置和文件名,並確保文件類型為原始的CAD繪圖文件格式(如.dwg格式)。
點擊「保存」按鈕。
注意,如果您是在共享的CAD圖紙中進行標注,則最好將修改後的文件保存為新的文件,而不是覆蓋原始文件,以免對其他人的工作造成影響。
『貳』 easy-poi導出Excel文件,默認文件名不對,怎麼修改
不知道是不是你上圖空格的原因造成的,我的程序(PHP)使用下面的語句是成功的,差異一是空格、二是大小寫,供你參考:
header('Content-Disposition: attachment; filename="mysql.xls"');
『叄』 如何修改spring mvc poi 導出excel文件
首先要導入spring相關包,poi,和fileupload包,我是使用maven構建的。
一.導入excel
(1)使用spring上傳文件
a.前台頁面提交
<form name="excelImportForm" action="${pageContext.request.contextPath}/brand/importBrandSort" method="post" onsubmit="return checkImportPath();" enctype="multipart/form-data" id="excelImportForm">
<input type="hidden" name="ids" id="ids">
<div class="modal-body">
<div class="row gap">
<label class="col-sm-7 control-label"><input class="btn btn-default" id="excel_file" type="file" name="filename" accept="xls"/></label>
<div class="col-sm-3">
<input class="btn btn-primary" id="excel_button" type="submit" value="導入Excel"/>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" onClick="uncheckBoxes();">取消</button>
</div>
b.後台spring的controller進行相關操作,這里主要講的是使用spring上傳文件,和讀取文件信息。
使用spring上傳文件之前,需要配置bean。
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>@RequestMapping(value = "/importBrandSort", method = RequestMethod.POST)
public ModelAndView importBrandSort(@RequestParam("filename") MultipartFile file,
HttpServletRequest request,HttpServletResponse response) throws Exception {
String temp = request.getSession().getServletContext()
.getRealPath(File.separator)
+ "temp"; // 臨時目錄
File tempFile = new File(temp);
if (!tempFile.exists()) {
tempFile.mkdirs();
}
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(10 * 1024 * 1024); // 設置允許用戶上傳文件大小,單位:位
fu.setSizeThreshold(4096); // 設置最多隻允許在內存中存儲的數據,單位:位
fu.setRepositoryPath(temp); // 設置一旦文件大小超過getSizeThreshold()的值時數據存放在硬碟的目錄
// 開始讀取上傳信息
//
int index = 0;
/* List fileItems = null;
try {
fileItems = fu.parseRequest(request);
}
catch (Exception e) {
e.printStackTrace();
}
Iterator iter = fileItems.iterator(); // 依次處理每個上傳的文件
FileItem fileItem = null;
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();// 忽略其他不是文件域的所有表單信息
if (!item.isFormField()) {
fileItem = item;
// index++;
}
}
if (fileItem == null)
return null;
*/
if (file == null)
return null;
logger.info(file.getOriginalFilename());
String name = file.getOriginalFilename();// 獲取上傳文件名,包括路徑
//name = name.substring(name.lastIndexOf("\\") + 1);// 從全路徑中提取文件名
long size = file.getSize();
if ((name == null || name.equals("")) && size == 0)
return null;
InputStream in = file.getInputStream();
List<BrandMobileInfoEntity> BrandMobileInfos = brandService
.importBrandPeriodSort(in);
// 改為人工刷新緩存KeyContextManager.clearPeriodCacheData(new
// PeriodDimensions());// 清理所有緩存
int count = BrandMobileInfos.size();
String strAlertMsg ="";
if(count!=0){
strAlertMsg= "成功導入" + count + "條!";
}else {
strAlertMsg = "導入失敗!";
}
logger.info(strAlertMsg);
//request.setAttribute("brandPeriodSortList", BrandMobileInfos);
//request.setAttribute("strAlertMsg", strAlertMsg);
request.getSession().setAttribute("msg",strAlertMsg);
return get(request, response);
//return null;
}
代碼中的注釋部分是如果不使用spring的方式,如何拿到提交過來的文件名(需要是要apache的一些工具包),其實使用spring的也是一樣,只是已經做好了封裝,方便我們寫代碼。
代碼中的後半部分是讀取完上傳文文件的信息和對資料庫進行更新之後,輸出到前台頁面的信息。
上述代碼中: InputStream in = file.getInputStream();
List<BrandMobileInfoEntity> BrandMobileInfos = brandService
.importBrandPeriodSort(in);讀取excel的信息。
(2)使用poi讀取excel
a.更新資料庫
@Override
public List<BrandMobileInfoEntity> importBrandPeriodSort(InputStream in) throws Exception {
List<BrandMobileInfoEntity> brandMobileInfos = readBrandPeriodSorXls(in);
for (BrandMobileInfoEntity brandMobileInfo : brandMobileInfos) {
mapper.updateByConditions(brandMobileInfo);
}
return brandMobileInfos;
}
這部分是sevice層的代碼,用於讀取excel信息之後更新資料庫數據,我這里是使用mybatis。定義一個類BrandMobileInfoEntity,用與保存excel表每一行的信息,而List< BrandMobileInfoEntity > 則保存了全部信息,利用這些信息對資料庫進行更新。
b.讀取excel信息
private List<BrandMobileInfoEntity> readBrandPeriodSorXls(InputStream is)
throws IOException, ParseException {
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
List<BrandMobileInfoEntity> brandMobileInfos = new ArrayList<BrandMobileInfoEntity>();
BrandMobileInfoEntity brandMobileInfo;
// 循環工作表Sheet
for (int numSheet = 0;
numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
if (hssfSheet == null) {
continue;
}
// 循環行Row
for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
brandMobileInfo = new BrandMobileInfoEntity();
HSSFRow hssfRow = hssfSheet.getRow(rowNum);
for (int i = 0; i < hssfRow.getLastCellNum(); i++) {
HSSFCell brandIdHSSFCell = hssfRow.getCell(i);
if (i == 0) {
brandMobileInfo.setBrandId(Integer
.parseInt(getCellValue(brandIdHSSFCell)));
} else if (i == 1) {
continue;
} else if (i == 2) {
brandMobileInfo.setMobileShowFrom(Integer.parseInt(getCellValue(brandIdHSSFCell)));
} else if (i == 3) {
brandMobileInfo.setMobileShowTo(Integer.parseInt(getCellValue(brandIdHSSFCell)));
} else if (i == 4) {
brandMobileInfo.setSellMarkValue(getCellValue(brandIdHSSFCell));
} else if (i == 5) {
brandMobileInfo.setWarehouse(getCellValue(brandIdHSSFCell));
} else if (i == 6) {
brandMobileInfo.setSortA1(Integer.parseInt(getCellValue(brandIdHSSFCell)));
} else if (i == 7) {
brandMobileInfo.setSortA2(Integer.parseInt(getCellValue(brandIdHSSFCell)));
} else if (i == 8) {
brandMobileInfo.setSortB(Integer.parseInt(getCellValue(brandIdHSSFCell)));
} else if (i == 9) {
brandMobileInfo.setSortC10(Integer.parseInt(getCellValue(brandIdHSSFCell)));
}
else if (i == 10) {
brandMobileInfo.setSortC(Integer.parseInt(getCellValue(brandIdHSSFCell)));
} else if (i == 11) {
brandMobileInfo.setHitA(getCellValue(brandIdHSSFCell));
} else if (i == 12) {
brandMobileInfo.setHitB(getCellValue(brandIdHSSFCell));
} else if (i == 13) {
brandMobileInfo.setHitC(getCellValue(brandIdHSSFCell));
} else if (i == 14) {
brandMobileInfo.setCustomSellType(getCellValue(brandIdHSSFCell));
}else if (i == 15)
{
continue;
}else if (i == 16) {
brandMobileInfo.setChannelId(Integer.parseInt(getCellValue(brandIdHSSFCell)));
}
}
brandMobileInfos.add(brandMobileInfo);
}
}
return brandMobileInfos;
}
這種代碼有點搓,還沒有優化,可以大概看到是怎麼讀取信息的。
(3)使用mybatis更新數據。
『肆』 POI導出excel表時文件名變成亂碼怎麼辦
在用POI進行excel表導出時,遇到中文文件名亂碼問題,用下面的方法得到了解決。
轉載自:https://my.oschina.NET/chinamummy29/blog/525639
在導出前對名稱根據瀏覽器做下處理
[java] view plain
<code class="hljs typescript" style=""><span class="hljs-comment" style="">// 判斷瀏覽器類型,firefox瀏覽器做特殊處理,否則下載文件名亂碼</span>
<span class="hljs-keyword" style="">public</span> <span class="hljs-keyword" style="">static</span> <span class="hljs-built_in" style="">void</span> compatibleFileName(HttpServletRequest request, HttpServletResponse response, <span class="hljs-built_in" style="">String</span> excelname) throws UnsupportedEncodingException {
<span class="hljs-built_in" style="">String</span> agent = request.getHeader(<span class="hljs-string" style="">"USER-AGENT"</span>).toLowerCase();
response.setContentType(<span class="hljs-string" style="">"application/vnd.ms-excel"</span>);
<span class="hljs-built_in" style="">String</span> fileName = excelname;
<span class="hljs-built_in" style="">String</span> codedFileName = java.net.URLEncoder.encode(fileName, <span class="hljs-string" style="">"UTF-8"</span>);
<span class="hljs-keyword" style="">if</span> (agent.contains(<span class="hljs-string" style="">"firefox"</span>)) {
response.setCharacterEncoding(<span class="hljs-string" style="">"utf-8"</span>);
response.setHeader(<span class="hljs-string" style="">"content-disposition"</span>, <span class="hljs-string" style="">"attachment;filename="</span> + <span class="hljs-keyword" style="">new</span> <span class="hljs-built_in" style="">String</span>(fileName.getBytes(), <span class="hljs-string" style="">"ISO8859-1"</span>) + <span class="hljs-string" style="">".xls"</span>);
} <span class="hljs-keyword" style="">else</span> {
response.setHeader(<span class="hljs-string" style="">"content-disposition"</span>, <span class="hljs-string" style="">"attachment;filename="</span> + codedFileName + <span class="hljs-string" style="">".xls"</span>);
}
}</code>