首页 \ 问答 \ 使用RUBY将值写入CSV列(Write value to CSV Column with RUBY)

使用RUBY将值写入CSV列(Write value to CSV Column with RUBY)

我有带标题的列如下:

First,Last,ID,Type

第一行数据如下所示:

Jon,Smith,123,,

第四列Type下没有值。

我有一个脚本可以将每个列解析为一个数组,并根据前三个条件( First,Last,ID执行不同的操作。

我需要写入CSV文件。 逻辑看起来像这样:

If First == Jon, Last == Smith, and ID == 123, write "Success" to Type

我有以下脚本:

   CSV.open("Content_File.csv", "wb") do |csv|
     csv << ["row", "of", "CSV", "data"]
     csv << ["another", "row"]

但它所做的只是逐行将内容写入CSV文件。 我需要写一个特定的行和一个特定的列。

有什么想法吗?


I have columns with headers as such:

First,Last,ID,Type

The first row of data looks like this:

Jon,Smith,123,,

There is no value under the fourth column Type.

I have a script that parses each column into an array and does different actions based on the first three criteria, First,Last,ID.

I need to write to the CSV file. The logic would look like this:

If First == Jon, Last == Smith, and ID == 123, write "Success" to Type

I have the following script:

   CSV.open("Content_File.csv", "wb") do |csv|
     csv << ["row", "of", "CSV", "data"]
     csv << ["another", "row"]

but all it does is write content to a CSV file row by row. I need to write to a specific row and a specific column.

Any thoughts?


原文:https://stackoverflow.com/questions/18393226
更新时间:2023-06-26 15:06

最满意答案

那么,用于居中#centered元素的CSS实际上是正确的! 所以不要担心,你在那里正确的轨道。

问题实际上在于#centered元素的内容 - .content元素的样式。 给定position:absolute ,这意味着它从布局中取出,因此#centered的定位#centered没有影响(因为#centered没有position:relative )。

有两种方法可以解决这个问题,我现在可以看到:首先,你可以添加position:relative对于#centered的定义,所以你的CSS看起来像这样:

#centered {
    width:900px;
    height:auto;
    margin:0px auto;
    position:relative;
}

这将导致您的绝对定位.content相对于#centered元素定位。 或者(和我喜欢的方法),你可以删除.content上的绝对定位,因为它似乎不需要在那里。 删除一些其他不必要的属性并添加一个边距,它看起来像这样:

.content {
    margin-top:115px;
    background:none;
}

这是第二个解决方案的JSFiddle演示 。 如果展开视口,您将看到元素现在在屏幕中居中。 请注意,如果您插入服务器端的内容不是绝对定位的(或者更确切地说,将在文档的流程中),则甚至不需要margin-top:115px ,因为您添加的任何内容都将只需根据需要向下推动.content元素即可。

如果这不是你想要的,请告诉我,我会很乐意进一步提供帮助。 祝你好运!


Well, your CSS for centering the #centered element is in fact correct! So don't worry, you were on the right track there.

The problem actually lies with the content of the #centered element - the styling of the .content element. It is given position:absolute, which means it gets taken out of the layout, and as such the positioning of #centered has no effect over it (since #centered does no have position:relative).

There are two ways to fix this that I can see right now: First, you could add position:relative to the definition for #centered, so your CSS looks like this:

#centered {
    width:900px;
    height:auto;
    margin:0px auto;
    position:relative;
}

This will cause your absolutely-positioned .content to be positioned relative to the #centered element. Alternatively (and the approach I prefer), you can remove the absolute positioning on .content, since it doesn't seem to needed to be there. With removal of some other attributes rendered unnecessary and adding of a margin instead, it would look like this:

.content {
    margin-top:115px;
    background:none;
}

Here's a JSFiddle demonstration of the second solution. If you expand the viewport, you'll see that the elements are now centered in the screen. Note that if the content you're inserting server-side won't be absolutely positioned (or rather, will be in the flow of the document), the margin-top:115px isn't even necessary, since any content you add will simply push the .content element downwards as needed.

If this isn't what you were looking for, let me know and I'll be happy to help further. Good luck!

相关问答

更多
  • 是的,使用行高和高度也很简单: .operation .itemText{ line-height: 15px; height: 30px; /* at least twice the line-height */ }
    Ring
    诀窍是将文本空间定 ...
  • 我知道这并不完全回答你的问题,但我认为你会发现这种方法更简单:) 在完整页面中查看片段 ,小片段容器不够大。 我建议只在您的链接中嵌套标记,而不是使用按钮的背景图像。 为什么? 因为那么容器(在这种情况下, li )将会增长以完美地匹配图像。 现在您不必设置每个按钮的宽度和高度,它们将根据图像大小增长。 为了在悬停时显示不同的图像,我会使用css选择器:hover来改变图像在0和1的不透明度。 此外,悬停图像应position到absolute position ,以便它可以出现在与非悬停 ...
  • 编辑我最后花了大约一个小时与OP聊天,他们问题的解决方案最终是从xc包中删除所有启动屏幕资产,而只是将UIImageView放在启动屏幕故事板上,将其每一侧锚定到视图的两侧,并将填充模式设置为纵横填充。 也就是说,我认为,以下信息更有可能为大多数遇到此问题的人解决问题。 对于不同的屏幕尺寸和纵横比,您需要不同尺寸的图像。 来自Apple文档 : 最好在启动屏幕上使用Xcode故事板,但如果需要,您可以提供一组静态图像。 为不同的设备创建不同大小的静态图像,并确保包含状态栏区域。 该文档包括一个大表,其中包含 ...
  • 你说“对象'从左上角飞过'的事实告诉我你的.OBJ没有居中,就像从3D编辑器导出它时,它没有居中。 它需要在3D创作程序中居中并再次导出。 The fact that you say "the object 'flies in' from the top left corner" suggests to me that your .OBJ is not centred, as in, when it was exported from the 3D editor, it was not centred. I ...
  • 感谢Gagravarr指出我正确的方向。 似乎我没有完整的ooxml-schemas-1.1.jar。 此代码现在可以完美地设置边距 CTSectPr sectPr = document.getDocument().getBody().addNewSectPr(); CTPageMar pageMar = sectPr.addNewPgMar(); pageMar.setLeft(BigInteger.valueOf(720L)); pageMar.setTop(BigInteger.valu ...
  • 那么,用于居中#centered元素的CSS实际上是正确的! 所以不要担心,你在那里正确的轨道。 问题实际上在于#centered元素的内容 - .content元素的样式。 给定position:absolute ,这意味着它从布局中取出,因此#centered的定位#centered没有影响(因为#centered没有position:relative )。 有两种方法可以解决这个问题,我现在可以看到:首先,你可以添加position:relative对于#centered的定义,所以你的CSS看起来像 ...
  • 不幸的是,似乎没有一种超快的方式来做到这一点,但以下是我的解决方案,至少似乎不依赖巧合。 在mdi构造函数中,调整大小: this.ResizeEnd += delegate { this.Refresh(); }; 然后这个覆盖处理最大化/恢复事件 protected override void WndProc(ref Message m) { if (m.Msg == Win32.WM_SYSCOMMAND) { int test ...
  • 我不太确定您将该代码放入的上下文,但这应该达到您想要的效果: #ftr_ctr { width: 100%; text-align: center; font-size:0.8em; position: absolute; height: 24px; } .hdr_lnk ul{ margin: auto; } .hdr_lnk li { display: inline; padding: 0; } 你需要的主要东西是width: 1 ...
  • 如flexbox规范中所述 : 在通过justify-content和align-self进行对齐之前,任何正的可用空间都会分配到该维度中的auto边距。 换句话说, auto边距优先于justify-content 。 在您的示例中,Chrome似乎符合规范。 (Firefox,以及。) 但IE11 - 在父母有justify-content - 忽略了margin-right: auto在弹性项目上margin-right: auto 。 这似乎是一个错误。 删除justify-content后, au ...
  • 你可以使用display: table; 在外部和display:table-cell内部容器上的display:table-cell ,用于垂直居中。 看一下这个: http://jsfiddle.net/NrCGb/578/ EDIT Max width 500px for content: http://jsfiddle.net/NrCGb/585/ You can work with display: table; on the outer and display:table-cell on the ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • 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)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置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])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)