如何使用C#

时间:2017-08-10 09:19:59

标签: c# excel uitableview filereader

我尝试过这段代码,但它不起作用:

private void Load_Button_Click(object sender, EventArgs e)
{
    using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Excel Workbook|*.xls", ValidateNames = true })
    {
        if (ofd.ShowDialog() == DialogResult.OK)
        {
             System.IO.FileStream fs = File.Open(ofd.FileName, System.IO.FileMode.Open, FileAccess.Read);
             ExcelDataReader.IExcelDataReader reader = ExcelDataReader.ExcelReaderFactory.CreateBinaryReader(fs);
             reader.IsFirstRowAsColumnNames = true;
             result = reader.AsDataSet();
             cboSheet.Items.Clear();

             foreach (DataTable dt in result.Tables)
                 cboSheet.Items.Add(dt.TableName);

             reader.Close();    
         }
     }
}

我似乎无法运行此代码,因为IsFirstRowAsColumnNamesAsDataSet有红色下划线。

我在这里找到了代码https://www.youtube.com/watch?v=7X3fTnuII7c

1 个答案:

答案 0 :(得分:2)

来自instructions for the library

  

安装<Style TargetType="{x:Type local:ClickableBorder}"> <Setter Property="BorderBrush" Value="Black"/> <Setter Property="Background" Value="LightGray"/> <Style.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True"/> <Condition Property="IsEnabled" Value="True"/> </MultiTrigger.Conditions> <MultiTrigger.EnterActions> <BeginStoryboard> <Storyboard> <ColorAnimation Duration="0:0:0.200" To="White" Storyboard.TargetProperty="BorderBrush.Color"/> <ColorAnimation Duration="0:0:0.200" To="DarkGray" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"/> </Storyboard> </BeginStoryboard> </MultiTrigger.EnterActions> <MultiTrigger.ExitActions> <BeginStoryboard> <Storyboard FillBehavior="Stop"> <ColorAnimation Duration="0:0:0.200" To="Black" Storyboard.TargetProperty="BorderBrush.Color"/> <ColorAnimation Duration="0:0:0.200" To="LightGray" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"/> </Storyboard> </BeginStoryboard> </MultiTrigger.ExitActions> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="local:FrameworkElementExt.IsPressed" Value="True"/> <Condition Property="IsEnabled" Value="True"/> </MultiTrigger.Conditions> <MultiTrigger.EnterActions> <BeginStoryboard> <Storyboard> <ColorAnimation Duration="0:0:0.200" To="DarkRed" Storyboard.TargetProperty="BorderBrush.Color"/> <ColorAnimation Duration="0:0:0.200" To="Red" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"/> </Storyboard> </BeginStoryboard> </MultiTrigger.EnterActions> <MultiTrigger.ExitActions> <BeginStoryboard> <Storyboard FillBehavior="Stop"> <ColorAnimation Duration="0:0:0.200" To="Black" Storyboard.TargetProperty="BorderBrush.Color"/> <ColorAnimation Duration="0:0:0.200" To="LightGray" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"/> </Storyboard> </BeginStoryboard> </MultiTrigger.ExitActions> </MultiTrigger> </Style.Triggers> </Style> 扩展程序包以使用ExcelDataReader.DataSet方法填充AsDataSet()

所以你需要additional library

System.Data.DataSet属性根本不存在,也许它是已删除的遗留项。相反,您似乎需要将配置传递给IsFirstRowAsColumnNames方法,例如:

AsDataSet