0.序言

之前帮朋友做了一个利用ISBN码批量查询图书信息的小工具,这个工具难度不大,对于书店、图书馆这些很多信息需要入库的单位而言有点作用,记录一下开发过程。先上程序截图:

1.程序原理

程序用到了Aspose.Cells.dll,这个库网上可以下载,主要用于表格读取写入。

**1.1.选择按钮:**用于选择存储ISBN信息的表格文件

if (openISBNFileDialog.ShowDialog() == DialogResult.OK)
{ISBNFilePathBox.Text = openISBNFileDialog.FileName;ISBNFilePath = openISBNFileDialog.FileName;Workbook workbook = new Workbook(ISBNFilePath);Cells cells = workbook.Worksheets[0].Cells;workState.Text = "共有" + (cells.MaxDataRow + 1) + "个ISBN码需要查询!";AnysisBtn.Enabled = true;
}

**1.2.分析按钮:**用于调用网络接口查询ISBN编码对应的图书信息

private void AnysisBtn_Click(object sender, EventArgs e)
{DownloadList.Rows.Clear();AnysisBtn.Enabled = false;Thread GetSoundIdsWork = new Thread(new ThreadStart(getDetail));GetSoundIdsWork.IsBackground = true;GetSoundIdsWork.Start();
}
private void getDetail()
{Workbook workbook = new Workbook(ISBNFilePath);Cells cells = workbook.Worksheets[0].Cells;bool isError = false;try{for (int i = 0; i < cells.MaxDataRow + 1; i++){workState.Text = "正在分析第" + (i + 1) + "/" + (cells.MaxDataRow + 1) + "个ISBN……";string ISBN = cells[i, 0].StringValue.Trim();string url = @"https://api.douban.com/v2/book/isbn/" + ISBN;string htmlStr = CommonMethds.GetWebClient(url);string authorTemp, author, publisherTemp, publisher, titleTemp, title, summaryTemp, summary, priceTemp, price;if (htmlStr == "数据库未收录该ISBN!"){isError = true;author = "无数据";publisher = "无数据";title = "无数据";summary = "无数据";price = "无数据";}else{try{authorTemp = htmlStr.Substring(htmlStr.IndexOf("\"author\":[\"") + 11);author = authorTemp.Substring(0, authorTemp.IndexOf("\"]")).Replace(@"\n", "").Replace(@"\/", ",").Replace("\"","").Trim();if (author == "")author = "无";}catch{authorTemp = htmlStr;author = "无";}publisherTemp = authorTemp.Substring(authorTemp.IndexOf("\"publisher\":\"") + 13);publisher = publisherTemp.Substring(0, publisherTemp.IndexOf("\",")).Replace(@"\n", "").Trim();if (publisher == "")publisher = "无";titleTemp = publisherTemp.Substring(publisherTemp.IndexOf("\"title\":\"") + 9);title = titleTemp.Substring(0, titleTemp.IndexOf("\",")).Replace(@"\n", "").Trim();if (title == "")title = "无";summaryTemp = titleTemp.Substring(titleTemp.IndexOf("\"summary\":\"") + 11);summary = summaryTemp.Substring(0, summaryTemp.IndexOf("\",")).Replace(@"\n", "").Trim();if (summary == "")summary = "无";priceTemp = summaryTemp.Substring(summaryTemp.IndexOf("\"price\":\"") + 9);price = priceTemp.Substring(0, priceTemp.IndexOf("\"}")).Replace(@"\n", "").Trim();if (price == "")price = "无";}int index = DownloadList.Rows.Add();DownloadList.Rows[index].Cells[0].Value = ISBN;DownloadList.Rows[index].Cells[1].Value = title;DownloadList.Rows[index].Cells[2].Value = author;DownloadList.Rows[index].Cells[3].Value = publisher;DownloadList.Rows[index].Cells[4].Value = price;DownloadList.Rows[index].Cells[5].Value = summary;DownloadList.Rows[index].Cells[6].Value = htmlStr;}if (isError)MessageBox.Show("查询完毕,部分图书未查询到!");elseMessageBox.Show("查询完毕!");AnysisBtn.Enabled = true;ToXlsBtn.Enabled = true;}catch (Exception ex){MessageBox.Show(ex.ToString());workState.Text = "网络连接失败!";AnysisBtn.Enabled = true;}
}

**1.3.导出按钮:**用于导出查询到的图书信息

private void ToXlsBtn_Click(object sender, EventArgs e)
{if (saveXlsFileDialog.ShowDialog() == DialogResult.OK){string xlsPath = saveXlsFileDialog.FileName;//定义表格Workbook UserData = new Workbook();Worksheet sheet = UserData.Worksheets[0];Cells cells = sheet.Cells;#region 定义表格样式sheet.PageSetup.TopMargin = 2.5;sheet.PageSetup.BottomMargin = 2.5;sheet.PageSetup.LeftMargin = 1.5;sheet.PageSetup.RightMargin = 1.5;//大标题样式Style style_header = UserData.Styles[UserData.Styles.Add()];style_header.HorizontalAlignment = TextAlignmentType.Center;//文字居中style_header.VerticalAlignment = TextAlignmentType.Center;style_header.Font.Name = "方正小标宋简体";//文字字体style_header.Font.Size = 22;//文字大小//小标题样式Style style_title = UserData.Styles[UserData.Styles.Add()];style_title.HorizontalAlignment = TextAlignmentType.Center;//文字居中style_title.VerticalAlignment = TextAlignmentType.Center;style_title.Font.Name = "黑体";//文字字体style_title.Font.Size = 11;//文字大小style_title.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界style_title.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界style_title.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界style_title.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界//内容样式Style style_common = UserData.Styles[UserData.Styles.Add()];style_common.HorizontalAlignment = TextAlignmentType.Center;style_common.VerticalAlignment = TextAlignmentType.Center;style_common.Font.Name = "宋体";style_common.Font.Size = 11;style_common.IsTextWrapped = true;  //自动换行style_common.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界style_common.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界style_common.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界style_common.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界//内容样式2Style style_common2 = UserData.Styles[UserData.Styles.Add()];style_common.VerticalAlignment = TextAlignmentType.Center;style_common2.Font.Name = "宋体";style_common2.Font.Size = 11;style_common2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界style_common2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界style_common2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界style_common2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界#endregion#region 设置行高cells.SetRowHeight(0, 40);cells.SetRowHeight(1, 20);#endregion#region 设置各列宽cells.SetColumnWidth(0, 20);//设置第1列宽cells.SetColumnWidth(1, 40);//设置第2列宽cells.SetColumnWidth(2, 30);//设置第3列宽cells.SetColumnWidth(3, 20);//设置第4列宽cells.SetColumnWidth(4, 20);//设置第5列宽cells.SetColumnWidth(5, 150);//设置第6列宽cells.SetColumnWidth(6, 150);//设置第7列宽#endregion#region 合并单元格//标题cells.Merge(0, 0, 1, 7);#endregion#region 设置公共内容cells[0, 0].Value = "ISBN查询结果";cells[0, 0].SetStyle(style_header);cells[1, 0].Value = "ISBN";cells[1, 0].SetStyle(style_title);cells[1, 1].Value = "书名";cells[1, 1].SetStyle(style_title);cells[1, 2].Value = "作者";cells[1, 2].SetStyle(style_title);cells[1, 3].Value = "出版社";cells[1, 3].SetStyle(style_title);cells[1, 4].Value = "价格";cells[1, 4].SetStyle(style_title);cells[1, 5].Value = "简介";cells[1, 5].SetStyle(style_title);cells[1, 6].Value = "源代码";cells[1, 6].SetStyle(style_title);#endregion#region 写入内容for (int i = 0; i < DownloadList.Rows.Count; i++){//行高cells.SetRowHeight(i + 2, 100);//ISBNcells[i + 2, 0].Value = DownloadList.Rows[i].Cells[0].Value.ToString();cells[i + 2, 0].SetStyle(style_common);//书名cells[i + 2, 1].Value = DownloadList.Rows[i].Cells[1].Value.ToString();cells[i + 2, 1].SetStyle(style_common);//作者cells[i + 2, 2].Value = DownloadList.Rows[i].Cells[2].Value.ToString();cells[i + 2, 2].SetStyle(style_common);//出版社cells[i + 2, 3].Value = DownloadList.Rows[i].Cells[3].Value.ToString();cells[i + 2, 3].SetStyle(style_common);//价格cells[i + 2, 4].Value = DownloadList.Rows[i].Cells[4].Value.ToString();cells[i + 2, 4].SetStyle(style_common);//简介cells[i + 2, 5].Value = DownloadList.Rows[i].Cells[5].Value.ToString();cells[i + 2, 5].SetStyle(style_common);//源代码cells[i + 2, 6].Value = DownloadList.Rows[i].Cells[6].Value.ToString();cells[i + 2, 6].SetStyle(style_common);}#endregionUserData.Save(xlsPath);MessageBox.Show("导出成功!");}
}

2.下载地址

贴个下载地址:https://download.csdn.net/download/mnikkqqw/10665121
使用问题联系我:mnikkqqw@126.com

[c#]图书ISBN信息批量查询工具开发手记相关推荐

  1. 网站域名过户查询_聚查教你怎么用域名批量查询工具查询网站历史和域名权重...

    购买老域名之前,要先查网站历史和域名权重,但是很多小编都找不到合适的域名批量查询工具,那么,聚查教你怎么用域名批量查询工具查询网站历史和域名权重. 一:域名批量查询工具查询网站历史和域名权重查询入口 ...

  2. 飘易关键字排名批量查询工具分享!

    正 文: 由于近期一直比较忙,前段时间答应一些朋友开发的 飘易关键字排名批量查询工具一直拖到了今天.昨天晚上抽了个完整的时间,把这个工具做出来了,今天分享给大家免费使用.     [前情提要]:    ...

  3. 在线域名批量查询工具-未注册域名批量查询软件

    在线域名批量查询工具 在线域名批量查询工具是一种通过互联网进行批量查询域名相关信息和指标的工具.以下是其主要特点: 在线查询:在线域名批量查询工具可以直接在浏览器中进行查询,无需下载和安装任何软件. ...

  4. 轻松解决批量查询问题——域名批量查询工具推荐

    在现代互联网时代,域名已成为了企业品牌和网站建设不可或缺的一部分.但是,对于需要大规模查询域名的人来说,手动逐一查询每个域名的可用情况无疑是一项耗时耗力的任务.幸运的是,现在有许多域名批量查询工具可以 ...

  5. 信息批量提取工具bulk-extractor

    信息批量提取工具bulk-extractor 在数字取证中,通常需要面对海量的数据,如几百GB甚至TB级别的数据.从这些海量数据中,提取有价值的数据是一个漫长.枯燥.繁琐的过程.Kali Linux提 ...

  6. SEO优化之—关键词批量查询工具

    关键词批量查询工具 批量查询某个网站的关键词排名是SEO人员必做的功课,不仅在研究竞争对手时要用到,自己网站优化前后都要定期查询,以检测优化效果,修改优化策略.这里介绍的批量查询工具就提供这样的功能. ...

  7. 百度收录批量查询-免费大量百度收录批量查询工具软件

    百度收录批量查询,为什么要使用百度收录批量查询,因为百度网站的收录状况,会反应一个网站的趋势,收录越多证明网站的状况越好.而百度收录批量查询工具就是大批量的查询网站的收录.今天给大家分享一个免费批量查 ...

  8. 360趋势批量查询工具

    介绍: 360趋势(360指数)批量查询工具支持下拉词采集 网盘下载地址: http://www.bytepan.net/JmWVdCSrCEr 图片:

  9. SEO工具:百度收录批量查询工具

    2019独角兽企业重金招聘Python工程师标准>>> 在前面我分享了我经常使用的PR批量查询工具,这次我分享的还是批量查询工具,这个也是非常实用的百度收录批量查询工具,这个网站就是 ...

最新文章

  1. Android--在程序里浏览网页/Webview的使用
  2. 天津海尔扫地机器人维修点_女神好帮手!海尔扫地机器人 让生活化繁为简
  3. Algorithms_入门基础_如何使用最高效的方式来判断一个数是否是2的N次方
  4. SAP Spartacus的defaultUrlMatcher
  5. hdu3579(中国剩余问题经典)
  6. 边缘计算精华问答 | 火爆的边缘计算为何兴起?
  7. 打通语言理论和统计 NLP 两个世界,Transformers/GNNs 架构能做到吗?
  8. dkplayer 延迟_阿里云播放器SDK使用说明
  9. ubuntu linux 教程 pdf,Ubuntu 12.04 菜鸟完全使用教程(二) PDF
  10. 中国城市名列表及code
  11. php过滤微信表情符号的正则表达式方法
  12. mysql数据库操作宠物表_mysql数据库及表的基本操作
  13. 本科毕业论文的引言怎么写?
  14. Alien Skin Exposure X7离线安装(PS/LR胶片滤镜模拟插件)
  15. 创建SpringMVC项目的基本步骤
  16. 2019年04月01日_拔剑-浆糊的传说_新浪博客
  17. Monte carlo 求解积分
  18. 开关电源三大拓扑之 Boost 电源中PFC电路是如何演变而来的
  19. h5酷炫粒子java代码_html5粒子效果文字特效
  20. 音频到文本转录有用的转录服务

热门文章

  1. UBUNTU 22.04 使用 SUNSHINE 和 MOONLIGHT 进行串流
  2. MS-DOS基本操作汇总
  3. 【CVPR 2021】Cylinder3D:用于LiDAR点云分割的圆柱体非对称3D卷积网络
  4. ESP Matter 环境搭建
  5. 专题三 Problem X
  6. 面积计算9860SD计算器程序(好用就用,不用就删-----歪XX)
  7. 软工实践 - 第二十二次作业 项目测评(团队)
  8. jmeter 接口测试 签名_Jmeter之API接口签名验证测试
  9. 计算机的声音图标打不开怎么回事,win10电脑音量图标打不开怎么办
  10. 开源项目-CRM客户关系管理系统