使用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
最满意答案
那么,用于居中
#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 givenposition: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 haveposition: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故事板,但如果需要,您可以提供一组静态图像。 为不同的设备创建不同大小的静态图像,并确保包含状态栏区域。 该文档包括一个大表,其中包含 ...
-
如何正确设置相机(How to correctly set the camera)[2023-07-27]
你说“对象'从左上角飞过'的事实告诉我你的.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 ... -
使用Apache poi设置边距(Set margins with Apache poi)[2023-01-30]
感谢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 ...