Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Aug 21, 2017
0 parents commit 0ca88e4
Show file tree
Hide file tree
Showing 68 changed files with 39,995 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
^.*\.Rproj$
^\.Rproj\.user$
^src/.*\.a$
^src/.*\.o$
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.Rproj.user
.Rhistory
.RData
*.so
*.o
*.a
15 changes: 15 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Package: writexl
Type: Package
Title: Export R Data Frames to xlsx Format
Version: 0.1
Authors@R: c(
person("Jeroen", "Ooms", ,"[email protected]", role = c("aut", "cre")),
person("John McNamara", role = "cph", comment = "Author of libxlsxwriter"))
Description: Light weight data frame to xlsx exporter based on libxlsxwriter.
No Java or Excel required.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
URL: https://libxlsxwriter.github.io (upstream)
RoxygenNote: 6.0.1
Suggests: readxl
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2017
COPYRIGHT HOLDER: Jeroen Ooms
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(lxw_version)
export(write_xlsx)
useDynLib(writexl,C_lxw_version)
useDynLib(writexl,C_write_data_frame)
11 changes: 11 additions & 0 deletions R/version.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#' Version
#'
#' Shows version of bundled libxlsxwriter.
#'
#' @export
#' @rdname writexl
#' @useDynLib writexl C_lxw_version
lxw_version <- function(){
version <- .Call(C_lxw_version)
as.numeric_version(version)
}
30 changes: 30 additions & 0 deletions R/write_xlsx.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#' Export to xlsx
#'
#' Writes a data frame to an xlsx file.
#'
#' @export
#' @aliases writexl
#' @useDynLib writexl C_write_data_frame
#' @param x data frame to write to disk
#' @param path a file name to write to
#' @param col_names write column names at the top of the file?
#' @examples tmp <- write_xlsx(iris)
#' readxl::read_xlsx(tmp)
write_xlsx <- function(x, path = tempfile(fileext = ".xlsx"), col_names = TRUE){
stopifnot(is.data.frame(x))
stopifnot(is.character(path))
df <- normalize_df(x)
headers <- if(isTRUE(col_names))
colnames(x)
.Call(C_write_data_frame, df, path, headers)
}

normalize_df <- function(df){
for(i in which(vapply(df, is.factor, logical(1)))){
df[[i]] <- as.character(df[[i]])
}
for(i in which(vapply(df, inherits, logical(1), "POSIXlt"))){
df[[i]] <- as.POSIXct(df[[i]])
}
df
}
23 changes: 23 additions & 0 deletions man/write_xlsx.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/writexl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
LIBXLSXWRITER = \
libxlsxwriter/app.o libxlsxwriter/format.o libxlsxwriter/theme.o \
libxlsxwriter/chart.o libxlsxwriter/hash_table.o libxlsxwriter/utility.o \
libxlsxwriter/content_types.o libxlsxwriter/packager.o libxlsxwriter/workbook.o \
libxlsxwriter/core.o libxlsxwriter/relationships.o libxlsxwriter/worksheet.o \
libxlsxwriter/custom.o libxlsxwriter/shared_strings.o libxlsxwriter/xmlwriter.o \
libxlsxwriter/drawing.o libxlsxwriter/styles.o tmpfileplus/tmpfileplus.o \
minizip/ioapi.o minizip/mztools.o minizip/zip.o minizip/unzip.o

STATICLIB=libxlsxwriter/libstatxlsxwriter.a

PKG_CFLAGS=$(C_VISIBILITY)
PKG_CPPFLAGS=-Iinclude
PKG_LIBS=-Llibxlsxwriter -lstatxlsxwriter -lz

all: clean

$(SHLIB): $(STATICLIB)

$(STATICLIB): $(LIBXLSXWRITER)
$(AR) rcs $(STATICLIB) $(LIBXLSXWRITER)

clean:
rm -f $(SHLIB) $(STATICLIB) $(OBJECTS) $(LIBXLSXWRITER)
23 changes: 23 additions & 0 deletions src/include/xlsxwriter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* libxlsxwriter
*
* Copyright 2014-2017, John McNamara, [email protected]. See LICENSE.txt.
*/

/**
* @file xlsxwriter.h
*
* xlsxwriter - A library for creating Excel XLSX files.
*
*/
#ifndef __LXW_XLSXWRITER_H__
#define __LXW_XLSXWRITER_H__

#include "xlsxwriter/workbook.h"
#include "xlsxwriter/worksheet.h"
#include "xlsxwriter/format.h"
#include "xlsxwriter/utility.h"

#define LXW_VERSION "0.7.4"

#endif /* __LXW_XLSXWRITER_H__ */
79 changes: 79 additions & 0 deletions src/include/xlsxwriter/app.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* libxlsxwriter
*
* Copyright 2014-2017, John McNamara, [email protected]. See LICENSE.txt.
*
* app - A libxlsxwriter library for creating Excel XLSX app files.
*
*/
#ifndef __LXW_APP_H__
#define __LXW_APP_H__

#include <stdint.h>
#include <string.h>
#include "workbook.h"
#include "common.h"

/* Define the queue.h TAILQ structs for the App structs. */
STAILQ_HEAD(lxw_heading_pairs, lxw_heading_pair);
STAILQ_HEAD(lxw_part_names, lxw_part_name);

typedef struct lxw_heading_pair {

char *key;
char *value;

STAILQ_ENTRY (lxw_heading_pair) list_pointers;

} lxw_heading_pair;

typedef struct lxw_part_name {

char *name;

STAILQ_ENTRY (lxw_part_name) list_pointers;

} lxw_part_name;

/* Struct to represent an App object. */
typedef struct lxw_app {

FILE *file;

struct lxw_heading_pairs *heading_pairs;
struct lxw_part_names *part_names;
lxw_doc_properties *properties;

uint32_t num_heading_pairs;
uint32_t num_part_names;

} lxw_app;


/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */

lxw_app *lxw_app_new();
void lxw_app_free(lxw_app *app);
void lxw_app_assemble_xml_file(lxw_app *self);
void lxw_app_add_part_name(lxw_app *self, const char *name);
void lxw_app_add_heading_pair(lxw_app *self, const char *key,
const char *value);

/* Declarations required for unit testing. */
#ifdef TESTING

STATIC void _app_xml_declaration(lxw_app *self);

#endif /* TESTING */

/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */

#endif /* __LXW_APP_H__ */
Loading

0 comments on commit 0ca88e4

Please sign in to comment.