首页 \ 问答 \ 将电子表格值转换为C#中的格式文本(Convert Spreadsheet values to Formated Text in C#)

将电子表格值转换为C#中的格式文本(Convert Spreadsheet values to Formated Text in C#)

我在电子表格中有一些值,如下例所示:

在此处输入图像描述

我总是至少有2列(可能很多),并且值之间总是有空行。

我想做的事情:复制这两列,粘贴在一个textBox中,当我按下一个按钮时,我希望这个文本的格式如下:

在此处输入图像描述

所以,基本上我需要:

  • 删除空行
  • 两列中的每个值都需要在单引号之间
  • 来自同一行(A1和B1)的值之间必须有逗号
  • 每行必须以“[”开头,以“]结束,”
  • 最后一行不得有结尾逗号。

是的,我需要的是将excel表转换为Java Script矩阵,以便在Selenium Web浏览器自动化上使用。

我已经做了一个帮助我很多的代码,但只是在excel中使用一个列,将其转换为一个简单的javascript向量,这里是代码:

String[] vector = textBox1.Text.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
String vectorFinal = String.Join("','", vector);
textBox2.Text = "'" + vectorFinal + "'";
Clipboard.SetText(textBox2.Text);

我刚刚开始研究C#,这就是为什么我仍然不知道如何去做。 处理多个列涉及TAB字符,这让我疯狂哈哈...提前感谢!


I have some values in a spreadsheet like this example:

enter image description here

I always have at least 2 columns (could be a lot) and also there are always empty lines between the values.

What I want to do: copy these 2 columns, paste in a textBox and when I press a button, I'd like to have this text formatted like this:

enter image description here

So, basically I need:

  • Remove empty lines
  • Each value from both columns needs to be between single quotes
  • The values from the same line (A1 and B1) must have a comma between them
  • Each line must start with "[" and end with "],"
  • The last line must not have the ending comma.

Yes, what I need is to convert a excel table to a Java Script matrix, to use on Selenium web browser automation.

I already did one code that's helping me a lot, but just with a single column in excel, to convert it to a simple javascript vector, here's the code:

String[] vector = textBox1.Text.Split(new String[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
String vectorFinal = String.Join("','", vector);
textBox2.Text = "'" + vectorFinal + "'";
Clipboard.SetText(textBox2.Text);

I'm just starting to study C#, that's why I still have no idea how to do it. Dealing with multiple columns involve TAB characters that are driving me crazy haha ... thanks in advance!


原文:https://stackoverflow.com/questions/28802241
更新时间:2021-05-08 06:05

最满意答案

主mPDF Github页面上的文档适用于开发版本。 还有现成的6.1.0版软件包 ,可以按原样上传和使用。

但是,我建议在本地通过composer安装mPDF,然后通过FTP或您使用的任何方式将整个本地安装传输到您的服务器。

由于作曲家现在是包裹管理的事实上的标准,未来版本的mPDF将不再提供那些预先准备好的包裹。


The documentation on the main mPDF Github page is for development version. There still are ready-to-use packages for version 6.1.0 which can be uploaded and used as-is.

However, I would recommend installing mPDF via composer locally and then transfer the whole local installation to your server via FTP or whatever you use.

As the composer is de-facto standard for package management now, future versions of mPDF will not provide those pre-prepared packages anymore.

相关问答

更多
  • 默认情况下,NPM依赖关系从NPM存储库中提取。 作者必须手动将其软件的新版本上传到NPM存储库,因此,NPM上托管的代码的“ @latest ”版本与任何地方存在的代码的最新版本(例如,GitHub上)不同。 根据Sails上的NPM存储库信息页面 ,最新的NPM托管版本是0.9.16而当前的GitHub版本是0.10.0-rc3 。 如果你想让你的项目依赖于特定的分支或者提交特定的Git仓库(而不是在NPM仓库中托管的版本),NPM开发者已经包含了一个明确的机制来允许这一点,在“ Git package ...
  • 你先运行brew update吗? 如果不这样做,Homebrew无法更新其公式,如果不更新其公式,则不知道如何安装最新版本的软件。 Have you run brew update first? If you don't do that, Homebrew can't update its formulas, and if it doesn't update its formulas it doesn't know how to install the latest versions of softwar ...
  • 它确实取决于应用程序设计运行的框架的版本,有几个版本的框架和一些运行时。 有时可以为.NET 3.5编写应用程序,但是引用了针对.NET 1.1编写的库,在这种情况下,您需要同时安装这两个库。 框架,运行时和语言参考有一个公平的分解在这个答案 。 It really depends on what version of the framework that the application was designed to run on, there are a few versions of the fram ...
  • 我相信你可以做到以下几点: sudo npm install soap@0.15.0 I believe you can do the following : sudo npm install soap@0.15.0
  • 主mPDF Github页面上的文档适用于开发版本。 还有现成的6.1.0版软件包 ,可以按原样上传和使用。 但是,我建议在本地通过composer安装mPDF,然后通过FTP或您使用的任何方式将整个本地安装传输到您的服务器。 由于作曲家现在是包裹管理的事实上的标准,未来版本的mPDF将不再提供那些预先准备好的包裹。 The documentation on the main mPDF Github page is for development version. There still are ready ...
  • 你可以使用RVM来安装ruby(它也会帮助你维护版本) 首先安装RVM gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB \curl -sSL https://get.rvm.io -o rvm.sh cat rvm.sh | bash -s stable source ~/.rvm/scri ...
  • 你可以做 rvm use ruby --latest --default You can do rvm use ruby --latest --default
  • 有两种选择。 最简单的方法可能是从Github安装,使用 devtools::install_github("rforge/rgl", subdir="pkg/rgl") 编辑添加:有一段时间这没有奏效,因为Github镜像没有被更新。 现在看起来好了,但如果它再次死亡,这个答案中描述的三种方法中唯一仍然有效的方法就是使用svn。 这会安装一个可能有几个小时的版本。 它确实需要你有用于源代码安装的工具; rgl有很多需要编译的代码。 这些工具可在Windows上使用, 网址为https://cloud.r ...
  • 使用他们已经提到的官方MongoDB文档如何安装您选择的版本。 安装Ubuntu 12.04和14.04的步骤 对于Ubuntu 16.04使用此功能 注意: -在此之前,请注意您没有MongoDB的任何现有存储库文件。 您可以使用sudo apt-get update进行检查。如果您有任何更新,则会显示更新。 如果你已经使用sudo rm /etc/apt/sources.list.d/mongodb*.list删除它,然后安装MongoDB On Ubuntu 16.04: sudo apt-key a ...
  • 确保package.json中有正确的版本,并且您没有将请求缓存到npm注册表。 您可以尝试删除本地(和全局)安装的模块并清除缓存。 还要确保您没有使用代理或私人注册表。 Make sure that you have a correct version in package.json and that you're not caching the requests to the npm registry. You may try to remove the locally (and globally) i ...

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)