小编Le *_*ung的帖子

在Excel中左,右,底部和顶部更改边框

首先,我将纸张的颜色边框更改为白色,因为我想要一张白纸.然后我做了一些标题,并想围绕它做边框.问题是它在标题中的值之间建立了边界,但顶部,向下是不可见的.

我的代码:

xlWorkSheet5.Columns.Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White); // Color Sheet5 to white, BusLoad
xlWorkSheet5.Columns.NumberFormat = "@";
Excel.Range rng = (Excel.Range)xlWorkSheet5.get_Range("A7","J7");
rng.RowHeight = 25.5;
rng.BorderAround2(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic);
rng.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
rng.Borders.Weight = 1d;
rng.Font.Bold = true;
rng.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
rng.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGray); 
Run Code Online (Sandbox Code Playgroud)

c# excel border

7
推荐指数
1
解决办法
3万
查看次数

将字符串拆分为数组,删除空格

我有一个关于拆分字符串的问题.我想拆分字符串,但在字符串中看到字符""然后不拆分并删除空格.

我的字符串:

String tmp = "abc 123 \"Edk k3\" String;";
Run Code Online (Sandbox Code Playgroud)

结果:

1: abc
2: 123
3: Edkk3  // don't split after "" and remove empty spaces
4: String
Run Code Online (Sandbox Code Playgroud)

我的结果代码,但我不知道如何删除""中的空格

var tmpList = tmp.Split(new[] { '"' }).SelectMany((s, i) =>
                {
                    if (i % 2 == 1) return new[] { s };
                    return s.Split(new[] { ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
                }).ToList();
Run Code Online (Sandbox Code Playgroud)

或者这不会看到"",所以它会分裂一切

string[] tmpList = tmp.Split(new Char[] { ' ', ';', '\"', ',' }, StringSplitOptions.RemoveEmptyEntries);
Run Code Online (Sandbox Code Playgroud)

.net c# arrays string split

5
推荐指数
1
解决办法
3万
查看次数

在datagridview中更改行backcolor

我在Windows窗体中更改行颜色时遇到问题.我用Columns做了它并为Rows尝试了相同但它没有用.有人可以告诉我该怎么做吗?

我的代码到目前为止:

 public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        abc();
    }

    void abc()
    {
        DataTable hh = new DataTable();
        hh.Columns.Add("1", typeof(string));
        hh.Columns.Add("2", typeof(string));
        hh.Columns.Add("3", typeof(string));

        hh.Rows.Add(new object[] { "a", "b", "c" });
        hh.Rows.Add(new object[] { "a1", "b1", "c1" });
        hh.Rows.Add(new object[] { "a2", "b2", "c2" });

        dataGridView1.DataSource = hh;

        foreach (DataGridViewRow dr in dataGridView1.Rows) // trying to change all rows to orange
            dr.DefaultCellStyle.BackColor = Color.Orange;  // but it doesn't work

        dataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.Orange; // doesn't work …
Run Code Online (Sandbox Code Playgroud)

c# datagridview backcolor winforms

2
推荐指数
1
解决办法
3万
查看次数

计算一些数学,错误"." 代替 ","

我想在C#中计算一些数学,但我有一个问题.我的数字都是用.而不是写的,.例如0.1而不是0,1.

(2^8 - 1)* 0.1 - 99.9
Run Code Online (Sandbox Code Playgroud)

因为所有这些都是字符串,我将它们转换为int.

我的代码:

 String factor = "0.1";
 String offset = "99.9";

 Int64 result = (Convert.ToInt64(Math.Pow(2, 8) - 1) * Convert.ToInt64(factor.ToString().Replace(".", ","))) + Convert.ToInt64(offset.ToString().Replace(".", ","));
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:"字符串格式不正确."

c# string math

0
推荐指数
1
解决办法
76
查看次数

标签 统计

c# ×4

string ×2

.net ×1

arrays ×1

backcolor ×1

border ×1

datagridview ×1

excel ×1

math ×1

split ×1

winforms ×1