Ejemplo n.º 1
0
        /// <summary>
        /// Adds a parameters section to the Tableau Workbook.
        /// </summary>
        private void AddParametersSection()
        {
            TableauDataSource parameters = new TableauDataSource("Parameters", WorkbookVersion);

            parameters.AddAttribute("hasconnection", "false");
            parameters.AddAttribute("inline", "true");
            datasources.Add(parameters);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds an Excel datasource to your Tableau file.
        /// </summary>
        /// <param name="filePath">File path to your Excel file.</param>
        /// <param name="dataSourceName">Data source name.</param>
        public void AddExcelTableDataSource(string filePath, string tableName, string dataSourceName)
        {
            FileInfo excelFile = new FileInfo(filePath);

            if (excelFile.Extension == ".xlsx")
            {
                TableauDataSource excelDataSource = new TableauDataSource(dataSourceName, WorkbookVersion);
                excelDataSource.AddAttribute("inline", "true");
                excelDataSource.DataConnection = new TableauDataConnection("excel-direct", excelFile.FullName);
                excelDataSource.DataConnection.AddAttribute("cleaning", "no");
                excelDataSource.DataConnection.AddAttribute("compat", "no");
                excelDataSource.DataConnection.AddAttribute("dataRefreshTime", "");
                excelDataSource.DataConnection.AddAttribute("validate", "no");
                excelDataSource.DataConnection.Relation = new TableauDataRelation(dataSourceName, "[" + tableName + "$]", "table");
                datasources.Add(excelDataSource);
            }
            else
            {
                throw new DataSourceNotCorrectTypeException(filePath, String.Format("{0} is not an Excel file.", filePath));
            }
        }
 public DataSourceNotCorrectTypeException(TableauDataSource dataSource, string message, Exception innerException) :
     base(message, innerException)
 {
     incorrectDataSource = dataSource;
 }
 protected DataSourceNotCorrectTypeException(TableauDataSource dataSource) :
     base(string.Format("{0} is not the type of datasource specified.", dataSource))
 {
     incorrectDataSource = dataSource;
 }